-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
None
-
Affects Version/s: 2.5.4
-
Component/s: None
-
None
-
ALL
-
None
-
None
-
None
-
None
-
None
-
None
-
None
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 }