[SERVER-43820] createIndex does not validate index option values Created: 03/Oct/19  Updated: 21/Oct/21  Resolved: 07/Oct/19

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: James Kovacs Assignee: Eric Milkie
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-26287 createIndexes should confirm that ind... Closed
Problem/Incident
Operating System: ALL
Sprint: Execution Team 2019-10-21
Participants:
Case:

 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.



 Comments   
Comment by Gabriel Marks [ 21/Oct/21 ]

This issue is resolved by a combination of the commits https://github.com/mongodb/mongo/commit/9537e7f9bd14ec7e097077b5a31e7a7db674114bhttps://github.com/mongodb/mongo/commit/c8e3d8c339141e4799b2c3519b54eb79025dea3dhttps://github.com/mongodb/mongo/commit/8d86a33ac0fb2decd8032b9d47f45bf0b388577d – the given createIndex call will fail. However, this only resolves the issue for newly created indexes – we aren't doing anything about indexes previously created with bad options.

Generated at Thu Feb 08 05:04:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.