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

Function BuildBatchUpdateSpec

pg_documentdb/src/commands/update.c:777–898  ·  view source on GitHub ↗

* BuildBatchUpdateSpec validates the update command BSON and builds * a BatchUpdateSpec. */

Source from the content-addressed store, hash-verified

775 * a BatchUpdateSpec.
776 */
777static BatchUpdateSpec *
778BuildBatchUpdateSpec(bson_iter_t *updateCommandIter, pgbsonsequence *updateDocs,
779 Datum *databaseNameDatum)
780{
781 const char *collectionName = NULL;
782 bool isOrdered = true;
783 bool bypassDocumentValidation = false;
784
785 bson_value_t let = { 0 };
786 bson_value_t updateValue = { 0 };
787 while (bson_iter_next(updateCommandIter))
788 {
789 const char *field = bson_iter_key(updateCommandIter);
790
791 if (strcmp(field, "update") == 0)
792 {
793 if (!BSON_ITER_HOLDS_UTF8(updateCommandIter))
794 {
795 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_BADVALUE),
796 errmsg("collection name has invalid type %s",
797 BsonIterTypeName(updateCommandIter))));
798 }
799
800 collectionName = bson_iter_utf8(updateCommandIter, NULL);
801 }
802 else if (strcmp(field, "updates") == 0)
803 {
804 EnsureTopLevelFieldType("update.updates", updateCommandIter, BSON_TYPE_ARRAY);
805
806 /* if both docs and spec are provided, fail */
807 if (updateDocs != NULL)
808 {
809 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_FAILEDTOPARSE),
810 errmsg("Unexpected further updates required")));
811 }
812
813 updateValue = *bson_iter_value(updateCommandIter);
814 }
815 else if (strcmp(field, "ordered") == 0)
816 {
817 EnsureTopLevelFieldType("update.ordered", updateCommandIter, BSON_TYPE_BOOL);
818
819 isOrdered = bson_iter_bool(updateCommandIter);
820 }
821 else if (strcmp(field, "bypassDocumentValidation") == 0)
822 {
823 /* TODO: unsupport by default */
824 if (!EnableBypassDocumentValidation)
825 {
826 continue;
827 }
828
829 EnsureTopLevelFieldType("update.bypassDocumentValidation", updateCommandIter,
830 BSON_TYPE_BOOL);
831
832 bypassDocumentValidation = bson_iter_bool(updateCommandIter);
833 }
834 else if (strcmp(field, "maxTimeMS") == 0)

Callers 1

PerformUpdateCoreFunction · 0.85

Tested by

no test coverage detected