[SERVER-5893] autoIndexId:true creates a non-unique index on _id Created: 22/May/12  Updated: 15/Aug/12  Resolved: 22/May/12

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

Type: Bug Priority: Major - P3
Reporter: Kevin Kwast Assignee: Scott Hernandez (Inactive)
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-5335 Creation of _id index should automati... Backlog
Related
related to DOCS-219 Indexing Chapter Closed
Operating System: Linux
Participants:

 Description   

According to http://www.mongodb.org/display/DOCS/Capped+Collections, setting autoIndexId:true should create a unique key index on the _id field (for replication of capped collections).

My capped collection got a non-unique index on _id instead:

> db.createCollection("myColl", {capped:true, size:536870912000, autoIndexId:true})
{ "ok" : 1 }
> db.myColl.getIndexes()
[
        {
                "v" : 1,
                "key" : {
                        "_id" : 1
                },
                "ns" : "dbname.myColl",
                "name" : "_id_"
        }
]

If the unique index on _id is no longer needed, this might be a documentation bug.



 Comments   
Comment by auto [ 22/Jun/12 ]

Author:

{u'date': u'2012-06-22T07:47:54-07:00', u'email': u'samk@10gen.com', u'name': u'Sam Kleinman'}

Message: SERVER-5893 _id index clarification
Branch: master
https://github.com/mongodb/docs/commit/64ee5252c0e9ec04c4923f6e7bd80f0c31ba7517

Comment by Kevin Kwast [ 22/May/12 ]

Thanks.

Comment by Scott Hernandez (Inactive) [ 22/May/12 ]

This is a problem with the index definition printed, not the creation. It is indeed a unique index:

> db.createCollection("cappedWithId", {capped:true, size:1000, max:2, autoIndexId:true})
> db.cappedWithId.insert({_id:1})
> db.cappedWithId.insert({_id:1})
duplicate key insert for unique index of capped collection

If you do the same with any collection you will see that for the _id index it doesn't print unique:true.

See SERVER-5335

Generated at Thu Feb 08 03:10:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.