Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-24903

Improve validation for index options

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Querying
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible

      Description

      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"
              }
      ]
      

        Attachments

          Activity

            People

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            david.hatch David Hatch
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: