Improve validation for index options

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • Query
    • Fully Compatible
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      Currently we don't restrict fields passed in index options to the createIndex command. This allows the user to store arbitrary data within the index spec. The full index spec is stored on disk, along with any data provided by the user that was not validated.

      The lack of validation impairs ease-of-use by silently failing when users provide invalid options. For example, suppose a user issues the shell command db.coll.createIndex({a: 1}, {locale: "en_US"}), intending to create a collation-aware index. The command will be accepted, but because the "collation" option should have been used instead, the index will not be collated. The user may not notice their mistake until the application exhibits behavior inconsistent with their expectations.

      The following shows an example of our current behavior:

      > coll.createIndex({a: 1}, {foo: "bar"});
      {
              "createdCollectionAutomatically" : true,
              "numIndexesBefore" : 1,
              "numIndexesAfter" : 2,
              "ok" : 1
      }
      > coll.getIndexes()
      [
              {
                      "v" : 1,
                      "key" : {
                              "_id" : 1
                      },
                      "name" : "_id_",
                      "ns" : "test.t"
              },
              {
                      "v" : 1,
                      "key" : {
                              "a" : 1
                      },
                      "name" : "a_1",
                      "ns" : "test.t",
                      "foo" : "bar"
              }
      ]
      

            Assignee:
            Backlog - Query Team (Inactive)
            Reporter:
            David Hatch (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: