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

Function ParseSpecSetCollModOptions

pg_documentdb/src/commands/coll_mod.c:356–534  ·  view source on GitHub ↗

* Parses the collMod Options received from GW, sets the option in `CollModOptions` * and also returns the `CollModSpecFlags` to represent which options were provided */

Source from the content-addressed store, hash-verified

354 * and also returns the `CollModSpecFlags` to represent which options were provided
355 */
356static CollModSpecFlags
357ParseSpecSetCollModOptions(const pgbson *collModSpec,
358 CollModOptions *collModOptions,
359 Datum *databaseNameDatum)
360{
361 Assert(collModSpec != NULL && collModOptions != NULL);
362
363 CollModSpecFlags specFlags = HAS_NO_OPTIONS;
364 bool hasSchemaValidation = false;
365
366 bson_iter_t iter;
367 PgbsonInitIterator(collModSpec, &iter);
368 while (bson_iter_next(&iter))
369 {
370 const char *key = bson_iter_key(&iter);
371 const bson_value_t *value = bson_iter_value(&iter);
372 if (strcmp(key, "collMod") == 0)
373 {
374 EnsureTopLevelFieldType("collMod.collMod", &iter, BSON_TYPE_UTF8);
375 collModOptions->collectionName = bson_iter_utf8(&iter, NULL);
376 }
377 else if (strcmp(key, "index") == 0)
378 {
379 EnsureTopLevelFieldType("collMod.index", &iter, BSON_TYPE_DOCUMENT);
380 bson_iter_t indexSpecIter;
381 bson_iter_recurse(&iter, &indexSpecIter);
382 ParseIndexSpecSetCollModOptions(&indexSpecIter, &(collModOptions->index),
383 &specFlags);
384 specFlags |= HAS_INDEX_OPTION;
385 }
386 else if (strcmp(key, "viewOn") == 0)
387 {
388 EnsureTopLevelFieldType("collMod.viewOn", &iter, BSON_TYPE_UTF8);
389 specFlags |= HAS_VIEW_OPTION;
390 collModOptions->viewDefinition.viewSource = pnstrdup(value->value.v_utf8.str,
391 value->value.v_utf8.len);
392 }
393 else if (strcmp(key, "pipeline") == 0)
394 {
395 EnsureTopLevelFieldType("collMod.pipeline", &iter, BSON_TYPE_ARRAY);
396 collModOptions->viewDefinition.pipeline = *value;
397 }
398 else if (strcmp(key, "colocation") == 0)
399 {
400 EnsureTopLevelFieldType("collMod.colocation", &iter, BSON_TYPE_DOCUMENT);
401 collModOptions->colocationOptions = *value;
402 specFlags |= HAS_COLOCATION;
403 }
404 else if (strcmp(key, "enableStats") == 0)
405 {
406 EnsureTopLevelFieldType("collMod.enableStats", &iter, BSON_TYPE_BOOL);
407 collModOptions->plannerStatistics = *value;
408 specFlags |= HAS_COLLECTION_PLANNER_STATISTICS;
409 }
410 else if (strcmp(key, "validator") == 0)
411 {
412 const bson_value_t *validator = ParseAndGetValidatorSpec(&iter,
413 "collMod.validator",

Callers 1

command_coll_modFunction · 0.85

Tested by

no test coverage detected