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

Function SerializeUpdateOneParams

pg_documentdb/src/commands/update.c:2727–2792  ·  view source on GitHub ↗

Serializes the update one params and shardkey bson as a pgbson to send down to the worker. */

Source from the content-addressed store, hash-verified

2725
2726/* Serializes the update one params and shardkey bson as a pgbson to send down to the worker. */
2727static pgbson *
2728SerializeUpdateOneParams(UpdateOneParams *params, pgbson *shardKeyBson)
2729{
2730 pgbson_writer commandWriter;
2731 PgbsonWriterInit(&commandWriter);
2732
2733 pgbson_writer writer;
2734 PgbsonWriterStartDocument(&commandWriter, "updateOne", -1, &writer);
2735
2736 if (params->query != NULL)
2737 {
2738 PgbsonWriterAppendValue(&writer, "query", -1, params->query);
2739 }
2740
2741 if (shardKeyBson != NULL)
2742 {
2743 PgbsonWriterAppendDocument(&writer, "shardKeyBson", -1, shardKeyBson);
2744 }
2745
2746 /* Back-compat (to handle new coordinator, old worker)
2747 * write it as a document that is { "": value }
2748 * TODO: See if this can be elided in the future
2749 */
2750 pgbson_writer valueWriter;
2751 PgbsonWriterStartDocument(&writer, "update", -1, &valueWriter);
2752 PgbsonWriterAppendValue(&valueWriter, "", 0, params->update);
2753 PgbsonWriterEndDocument(&writer, &valueWriter);
2754
2755 PgbsonWriterAppendBool(&writer, "isUpsert", -1, params->isUpsert != 0);
2756
2757 PgbsonWriterAppendBool(&writer, "bypassDocumentValidation", -1,
2758 params->bypassDocumentValidation);
2759
2760 if (params->sort != NULL)
2761 {
2762 PgbsonWriterAppendValue(&writer, "sort", 4, params->sort);
2763 }
2764
2765 PgbsonWriterAppendInt32(&writer, "returnDocument", -1, (int) params->returnDocument);
2766
2767 if (params->returnFields != NULL)
2768 {
2769 PgbsonWriterAppendValue(&writer, "returnFields", -1, params->returnFields);
2770 }
2771
2772 if (params->arrayFilters != NULL)
2773 {
2774 /*
2775 * back compat: To handle new coordinator old worker scenario, write it in the
2776 * prior format of { "": value }
2777 * TODO: See if this can be elided in the future
2778 */
2779 PgbsonWriterStartDocument(&writer, "arrayFilters", -1, &valueWriter);
2780 PgbsonWriterAppendValue(&valueWriter, "", 0, params->arrayFilters);
2781 PgbsonWriterEndDocument(&writer, &valueWriter);
2782 }
2783
2784 if (params->variableSpec != NULL &&

Callers 1

Calls 8

PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendValueFunction · 0.85
PgbsonWriterEndDocumentFunction · 0.85
PgbsonWriterAppendBoolFunction · 0.85
PgbsonWriterAppendInt32Function · 0.85
PgbsonWriterGetPgbsonFunction · 0.85

Tested by

no test coverage detected