|
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.
|