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

createIndex does not validate index option values

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • ALL
    • Execution Team 2019-10-21

      When creating an index, createIndex will validate that the index option keys are valid. The following index definition is not valid because there is no spork option:

      > db.COLL.createIndex({a:1},{spork:true})
      {
        "ok": 0,
        "errmsg": "The field 'spork' is not valid for an index specification. Specification: { key: { a: 1.0 }, name: \"a_1\", spork: true }",
        "code": 197,
        "codeName": "InvalidIndexSpecificationOption"
      }
      

      However an invalid option value for a known option key will succeed:

      > db.COLL.createIndex({a:1},{sparse:"PanGalacticGargleBlaster"})
      {
        "createdCollectionAutomatically": true,
        "numIndexesBefore": 1,
        "numIndexesAfter": 2,
        "ok": 1
      }
      

      This can cause problems for other tooling that assumes sparse will always be a boolean value. Even more insidious is in cases such as sparse:1 rather than sparse:true.

      The same problem can be observed with background and other index options.

            Assignee:
            milkie@mongodb.com Eric Milkie
            Reporter:
            james.kovacs@mongodb.com James Kovacs
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: