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

Function ParseDropIndexesArg

pg_documentdb/src/commands/drop_indexes.c:555–685  ·  view source on GitHub ↗

* ParseDropIndexesArg returns a DropIndexesArg object by parsing given * pgbson object that represents the "arg" document passed to * dbCommand/dropIndexes. */

Source from the content-addressed store, hash-verified

553 * dbCommand/dropIndexes.
554 */
555static DropIndexesArg
556ParseDropIndexesArg(pgbson *arg, Datum *databaseNameDatum)
557{
558 DropIndexesArg dropIndexesArg = { 0 };
559
560 /*
561 * Distinguish "index: []" from not specifying "index" field at all.
562 * While the former one is ok, the later one is not.
563 */
564 bool gotIndexObject = false;
565
566 bson_iter_t argIter;
567 PgbsonInitIterator(arg, &argIter);
568 while (bson_iter_next(&argIter))
569 {
570 /*
571 * we don't throw an error if we encounter with
572 * definition of a field more than once.
573 *
574 * TODO: We should also not throw an error if there is a syntax error
575 * in the preceding definitions. That means, even if the first
576 * definiton of "index" uses an integer, we should not throw an
577 * error for the following, since later definition is valid:
578 * {"index": 1, "index": "my_index_name"}
579 */
580
581 const char *argKey = bson_iter_key(&argIter);
582
583 /*
584 * The "deleteIndexes" command is deprecated but still accepted as an alias for "dropIndexes".
585 * The input and error handling are consistent with "dropIndexes", so no special handling is required.
586 */
587 if (strcmp(argKey, "dropIndexes") == 0 ||
588 strcmp(argKey, "deleteIndexes") == 0)
589 {
590 EnsureTopLevelFieldType("dropIndexes.dropIndexes", &argIter, BSON_TYPE_UTF8);
591
592 const bson_value_t *dropIndexesVal = bson_iter_value(&argIter);
593 dropIndexesArg.collectionName = pstrdup(dropIndexesVal->value.v_utf8.str);
594 }
595 else if (strcmp(argKey, "index") == 0)
596 {
597 gotIndexObject = true;
598 dropIndexesArg.dropIndexMode = DROP_INDEX_MODE_INVALID;
599
600 if (BSON_ITER_HOLDS_UTF8(&argIter))
601 {
602 const bson_value_t *indexVal = bson_iter_value(&argIter);
603 dropIndexesArg.index.nameList =
604 list_make1(pstrdup(indexVal->value.v_utf8.str));
605 dropIndexesArg.dropIndexMode = DROP_INDEX_BY_NAME_LIST;
606 }
607 else if (BSON_ITER_HOLDS_DOCUMENT(&argIter))
608 {
609 dropIndexesArg.index.document = PgbsonInitFromIterDocumentValue(&argIter);
610 dropIndexesArg.dropIndexMode = DROP_INDEX_BY_SPEC_DOCUMENT;
611 }
612 else if (BSON_ITER_HOLDS_ARRAY(&argIter))

Tested by

no test coverage detected