-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 1.8.4, 2.0.1
-
Component/s: Write Ops
-
Environment:All
-
ALL
findAndModify throws exception when _id is in the update document and "new":true
Even though an exception is thrown, the document is still inserted.
This was generated from http://groups.google.com/group/mongodb-user/browse_thread/thread/00623298f8c04836
To Reproduce in 2.0.1: (This is reproducible in 1.8.4 as well, although the outputs are slightly different. )
> db.test.drop()
true
> db.test.save({_id:1, "name" : "Object 1"})
> db.runCommand({findAndModify:"test", "query" :
, "update" :
{ "_id" : 2, "name" : "Object 2" }, "upsert" : true } )
{
"lastErrorObject" :
,
"value" : {
},
"ok" : 1
}
> db.test.find()
> db.runCommand({findAndModify:"test", "query" :
{ "name" : "asdf" }, "update" :
{ "_id" : 3, "name" : "Object 3" }, "upsert" : true, "new":true } )
{
"lastErrorObject" :
,
"errmsg" : "exception: assertion db/ops/../../util/net/../../db/../bson/bsonobjbuilder.h:127",
"code" : 0,
"ok" : 0
}
> db.test.find()
Adding a value (any value) to the _id key in the query document prevents an exception from being thrown.
(Example done with 2.0.1)
> db.runCommand({findAndModify:"test", "query" :
, "update" :
{ "_id" : 4, "name" : "Object 4" }, "upsert" : true, "new":true } )
{
"lastErrorObject" :
,
"value" : {
},
"ok" : 1
}
> db.runCommand({findAndModify:"test", "query" :
, "update" :
{ "_id" : 5, "name" : "Object 5" }, "upsert" : true, "new":true } )
{
"lastErrorObject" :
,
"value" :
,
"ok" : 1
}
> db.runCommand({findAndModify:"test", "query" :
, "update" :
{ "_id" : 6, "name" : "Object 6" }, "upsert" : true, "new":true } )
{
"lastErrorObject" :
,
"value" :
,
"ok" : 1
}
- duplicates
-
SERVER-6913 update allows upsert to "modify" _id
- Closed