[SERVER-24903] Improve validation for index options Created: 05/Jul/16  Updated: 06/Dec/22  Resolved: 05/Jul/16

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

Type: Improvement Priority: Major - P3
Reporter: David Hatch Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query
Backwards Compatibility: Fully Compatible
Participants:

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



 Comments   
Comment by David Hatch [ 05/Jul/16 ]

Closed as duplicate of SERVER-769.

Comment by Eric Milkie [ 05/Jul/16 ]

SERVER-769?

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