MCPcopy Create free account
hub / github.com/documentdb/documentdb / BuildResponseMessage

Function BuildResponseMessage

pg_documentdb/src/commands/find_and_modify.c:624–669  ·  view source on GitHub ↗

* BuildResponseMessage returns a bson object that can be sent to the client * based on given FindAndModifyResult. */

Source from the content-addressed store, hash-verified

622 * based on given FindAndModifyResult.
623 */
624static pgbson *
625BuildResponseMessage(FindAndModifyResult *result)
626{
627 pgbson_writer lastErrorObjectWriter;
628 PgbsonWriterInit(&lastErrorObjectWriter);
629
630 PgbsonWriterAppendInt32(&lastErrorObjectWriter, "n", strlen("n"),
631 result->lastErrorObject.n);
632
633 if (result->isUpdateCommand)
634 {
635 PgbsonWriterAppendBool(&lastErrorObjectWriter, "updatedExisting",
636 strlen("updatedExisting"),
637 result->lastErrorObject.updatedExisting);
638
639 if (result->lastErrorObject.upsertedObjectId != NULL)
640 {
641 pgbsonelement idElement;
642 PgbsonToSinglePgbsonElement(result->lastErrorObject.upsertedObjectId,
643 &idElement);
644 PgbsonWriterAppendValue(&lastErrorObjectWriter, "upserted",
645 strlen("upserted"),
646 &idElement.bsonValue);
647 }
648 }
649
650 pgbson_writer resultWriter;
651 PgbsonWriterInit(&resultWriter);
652
653 PgbsonWriterAppendDocument(&resultWriter, "lastErrorObject",
654 strlen("lastErrorObject"),
655 PgbsonWriterGetPgbson(&lastErrorObjectWriter));
656 if (result->value == NULL)
657 {
658 PgbsonWriterAppendNull(&resultWriter, "value", strlen("value"));
659 }
660 else
661 {
662 PgbsonWriterAppendDocument(&resultWriter, "value", strlen("value"),
663 result->value);
664 }
665
666 PgbsonWriterAppendDouble(&resultWriter, "ok", strlen("ok"), result->ok);
667
668 return PgbsonWriterGetPgbson(&resultWriter);
669}

Callers 1

command_find_and_modifyFunction · 0.70

Calls 9

PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendInt32Function · 0.85
PgbsonWriterAppendBoolFunction · 0.85
PgbsonWriterAppendValueFunction · 0.85
PgbsonWriterGetPgbsonFunction · 0.85
PgbsonWriterAppendNullFunction · 0.85
PgbsonWriterAppendDoubleFunction · 0.85

Tested by

no test coverage detected