[SERVER-26724] createIndexes command should reject invalid options for _id index Created: 21/Oct/16  Updated: 31/Oct/16  Resolved: 27/Oct/16

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

Type: Improvement Priority: Major - P3
Reporter: Tess Avitabile (Inactive) Assignee: Tess Avitabile (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Minor Change
Sprint: Query 2016-10-31
Participants:

 Description   

When an _id index is implicitly created through collection creation, it can only include the fields key, name, v, ns, and collation. However, when you use the createIndexes command, it accepts any valid index option except {sparse: true}, {unique: false}, and partialFilterExpression. This leads to unusual specs for the _id index.

> db.createCollection("c")
> db.c.getIndexes()
[
    {
        "v" : 2,
        "key" : {
                   "_id" : 1
        },
        "name" : "_id_",
        "ns" : "test.c"
    }
]
> db.c.drop()
> db.createCollection("c", {autoIndexId: false})
> db.c.createIndexes({_id: 1}, {unique: true})
> db.c.getIndexes()
[
    {
        "v" : 2,
        "key" : {
                   "_id" : 1
        },
        "name" : "_id_",
        "ns" : "test.c",
        "unique" : true
    }
]

Worse, it lets you create _id indexes like:

> db.createCollection("c", {autoIndexId: false})
> db.c.createIndexes({_id: 1}, {expireAfterSeconds: 3600})
> db.c.getIndexes()
[
    {
        "v" : 2,
        "key" : {
                   "_id" : 1
        },
        "name" : "_id_",
        "ns" : "test.c",
        "expireAfterSeconds" : 3600
    }
]

This would lead us to erroneously believe that an old _id index with this option was a TTL index. We should reject all options besides key, name, v, ns, and collation for _id indexes created through createIndexes.

Note: If you try to create an index with key pattern other than {_id: 1} and name "_id_", this succeeds. Instead, we should reject the command.



 Comments   
Comment by Githook User [ 27/Oct/16 ]

Author:

{u'username': u'tessavitabile', u'name': u'Tess Avitabile', u'email': u'tess.avitabile@mongodb.com'}

Message: SERVER-26724 createIndexes command should reject invalid options for _id index
Branch: master
https://github.com/mongodb/mongo/commit/79c2bc2f73138a1859c5d8ea91dc6f60e67ae8b8

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