[SERVER-11631] Collections created by an update write command don't get an _id_ index Created: 08/Nov/13  Updated: 11/Jul/16  Resolved: 08/Nov/13

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

Type: Bug Priority: Major - P3
Reporter: Bernie Hackett Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Operating System: ALL
Participants:

 Description   

If the first document in a collection is upserted using the new update command subsequent duplicate _id inserts succeed:

> db.dropDatabase()
{ "dropped" : "foo", "ok" : 1 }
> 
> db.runCommand({update: 'bar', updates: [{q: {_id: 1}, u: {}, upsert: true}]})
{ "ok" : 1, "n" : 1, "upserted" : 1 }
> db.bar.insert({'_id': 1})
> db.bar.insert({'_id': 1})
> db.bar.insert({'_id': 1})
> db.bar.insert({'_id': 1})
> 
> db.bar.find()
{ "_id" : 1 }
{ "_id" : 1 }
{ "_id" : 1 }
{ "_id" : 1 }
{ "_id" : 1 }

The new insert command does not cause the same problem:

> db.dropDatabase()
{ "dropped" : "foo", "ok" : 1 }
> db.runCommand({insert: 'bar', documents: [{_id: 1}]})
{ "ok" : 1, "n" : 1 }
> db.bar.insert({'_id': 1})
E11000 duplicate key error index: foo.bar.$_id_  dup key: { : 1.0 }



 Comments   
Comment by Bernie Hackett [ 08/Nov/13 ]

Fixed by commits related to SERVER-11611.

Comment by Bernie Hackett [ 08/Nov/13 ]

eliot, I see you just pushed some commits related to this for SERVER-11611. That does seem to fix the problem:

2013-11-07T17:59:19.784-0800 [initandlisten] db version v2.5.4-pre-
2013-11-07T17:59:19.784-0800 [initandlisten] git version: cf0103d736d93d14f1b3eaa7fe3e97a2c77a8080

> db.dropDatabase()
{ "dropped" : "foo", "ok" : 1 }
> db.runCommand({update: 'bar', updates: [{q: {_id: 1}, u: {}, upsert: true}]})
{ "ok" : 1, "n" : 1, "upserted" : 1 }
> db.bar.find()
{ "_id" : 1 }
> db.bar.getIndexes()
[
	{
		"v" : 1,
		"key" : {
			"_id" : 1
		},
		"name" : "_id_",
		"ns" : "foo.bar"
	}
]
> db.bar.insert({_id: 1})
E11000 duplicate key error index: foo.bar.$_id_  dup key: { : 1.0 }

Comment by Bernie Hackett [ 08/Nov/13 ]

2013-11-07T17:39:46.396-0800 [initandlisten] db version v2.5.4-pre-
2013-11-07T17:39:46.396-0800 [initandlisten] git version: 75fdb3e7312adcf187985a90e3c6f3700be1c20e

Pulled this morning. I'll pull, rebuild, and try again.

Comment by Eliot Horowitz (Inactive) [ 08/Nov/13 ]

What hash? There was a bug in some heads.
Try with the latest.

Comment by Bernie Hackett [ 08/Nov/13 ]

schwerin, that would appear to be the problem. The _id_ index isn't being created. I've updated the subject.

> db.dropDatabase()
{ "dropped" : "foo", "ok" : 1 }
> db.runCommand({update: 'bar', updates: [{q: {_id: 1}, u: {}, upsert: true}]})
{ "ok" : 1, "n" : 1, "upserted" : 1 }
> db.bar.getIndexes()
[ ]

Comment by Andy Schwerin [ 08/Nov/13 ]

Is there an index on _id? Looks like that's the likely culprit.

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