[SERVER-26514] Create command should take idIndex option Created: 07/Oct/16  Updated: 17/May/19  Resolved: 24/Oct/16

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

Type: Task 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

Issue Links:
Depends
Documented
is documented by DOCS-9474 Docs for SERVER-26514: Create command... Closed
Related
is related to SERVER-26887 Idempotency of createCollection with ... Closed
Backwards Compatibility: Fully Compatible
Sprint: Query 2016-10-31
Participants:

 Description   

The create command should take the full _id index spec as the idIndex option.

> db.runCommand({create: "c", 
idIndex: {v: 1, key: {_id: 1}, name: “_id_”, ns: “test.c”}})

Required options are "key" and "name". "key" must be _id: 1 and "name" must be "_id_". No options are allowed other than "key", "name", "v", "ns", and "collation".

If the "collation" differs from the collection default collation, we reject the command. If "collation" is not present, the _id index inherits the collection default collation.

If "v" is not present, it is set to 2 if featureCompatibilityVersion=3.4 and 1 if featureCompatibilityVersion=3.2.



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

Author:

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

Message: SERVER-26514 Create command should take idIndex option
Branch: master
https://github.com/mongodb/mongo/commit/064ed7fab88447bd5dd6bfc19dfef4dbf89d19f9

Comment by Tess Avitabile (Inactive) [ 20/Oct/16 ]

steve.briskin, we would like to require that the idIndex option does not contain any fields other than key, name, ns, v, and collation. These are the only fields in the spec for the _id index implicitly created by the create command. However, it is possible to create an _id index with other fields, by explicitly creating the _id index:

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

This means that if a user had generated an _id index this way and included extra fields, you would not be able to back up this collection.

How does that sound to you? We hope that _id indexes generated this way are rare, and we do not want to make it easy for users to create _id indexes with extra fields.

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