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

createIndex does not validate index option values

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • None
    • None
    • None
    • None
    • ALL
    • Execution Team 2019-10-21

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: