-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
None
-
Affects Version/s: 1.6.5
-
Component/s: None
-
None
-
Environment:Mac OS X 10.6.6; MongoDB 1.6.5
-
Fully Compatible
-
ALL
-
None
-
3
-
None
-
None
-
None
-
None
-
None
-
None
When using the "findAndModify" command, "getLastError" only returns the result of the last of the two operations. By default, this means it returns the result of the "update" operation (which is normally desirable), but when one uses the "new" option, getLastError returns the result of the "find" operation, so any error in the update clause is inaccessible.
The following sequence of commands demonstrates the problem:
db.test.insert(
)
db.test.findAndModify({query:
, update: {$set:
{age: 30}, $inc: {age: 3}}, new: true})
db.getLastError()
Ideally, what you should receive when you run the last line, db.getLastError(), you should get an error "Field name duplication not allowed with modifiers". Instead, you get null, as the find operation (the 2nd of the two internal operations), succeeded. If you had the "new" option set to false, and you had a similar error in the find/query portion of the command, you'd get the same problem.