-
Type: Bug
-
Resolution: Done
-
Priority: Critical - P2
-
Affects Version/s: 2.4.10
-
Component/s: Index Maintenance
-
None
-
Fully Compatible
-
ALL
-
ISSUE SUMMARY
It is possible to create multiple _id indexes on a collection using ensureIndex({_id:-1}).
db.foo.ensureIndex({_id:-1}) db.foo.ensureIndex({_id:-1}) db.foo.ensureIndex({_id:-1}) db.foo.getIndexes().length 4
Although having multiple _id indexes on a collection is not intended behavior, the collection may be usable in this state. However, an attempt to subsequently drop such a collection corrupts the namespace:
db.foo.drop() Fri Aug 8 16:43:48.593 drop failed: { "nIndexesWas" : 4, "errmsg" : "exception: drop: dropIndexes for collection failed - consider trying repair cause: BSONObj size: 0 (0x00000000) is invalid. Size must be between 0 and 16793600(16MB) First element: EOO", "code" : 12503, "ok" : 0 } at src/mongo/shell/collection.js:383
USER IMPACT
The affected namespace is corrupted upon collection drop, and cannot be used until it is repaired.
WORKAROUNDS
Create _id indexes with ensureIndex({_id: 1}) instead of ensureIndex({_id: -1}). If the indexes have already been created and the affected collection needs to be dropped, run db.repairDatabase() afterwards to fix the namespace corruption.
AFFECTED VERSIONS
MongoDB 2.4 production releases are affected by this issue.
FIX VERSION
The fix is included in the 2.4.11 production release.
RESOLUTION DETAILS
Reject ensureIndex({{_id:-1}) requests if the _id index already exists.
Original description
Affects only 2.4 branch (issue not in 2.6.3 nor in master as of 7 Aug 2014 GMT)
You can insert the same descending _id index multiple times, as they are inserting as ascending each time.
Create a descending _id index:
db.foo.ensureIndex({_id:-1}); db.foo.ensureIndex({_id:-1}); db.foo.ensureIndex({_id:-1});
Check the count
> db.foo.getIndexes().length 4
We have created the same index 3 times.
Attempting to drop the collection will corrupt the namespace
> db.foo.drop(); Fri Aug 8 16:43:48.593 drop failed: { "nIndexesWas" : 4, "errmsg" : "exception: drop: dropIndexes for collection failed - consider trying repair cause: BSONObj size: 0 (0x00000000) is invalid. Size must be between 0 and 16793600(16MB) First element: EOO", "code" : 12503, "ok" : 0 } at src/mongo/shell/collection.js:383
- related to
-
SERVER-14849 Creating descending _id index should result in error
- Backlog
-
SERVER-14848 Port index_id_desc.js to v2.6 and master branches
- Closed