Details
-
Improvement
-
Resolution: Won't Fix
-
Minor - P4
-
None
-
2.6.0-rc2
-
None
Description
$unset should get an error on negative array indices, like $pop and $pull do
Step 1.
Add a document with an array:
> db.test.drop()
|
> db.test.insert({_id : 1, a : [1, 2]})
|
Step 2.
Try to $unset at an invalid negative index:
> db.test.update({_id : 1}, {$unset : {"a.-2" : 1}})
|
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
|
Actual result:
The operation is silently ignored.
Expected result:
An error should be returned, like in $pop and $pull cases.
Step 3.
Compare with $pop and $pull invoked with negative indices, they return expected errors:
> db.test.update({_id : 1}, {$pop : {"a.-2" : 1}})
|
WriteResult({
|
"nMatched" : 0,
|
"nUpserted" : 0,
|
"nModified" : 0,
|
"writeError" : {
|
"code" : 16837,
|
"errmsg" : "cannot use the part (a of a.-2) to traverse the element ({a: [ 1.0, 2.0 ]})"
|
}
|
})
|
|
|
> db.test.update({_id : 1}, {$pull : {"a.-2" : 1}})
|
WriteResult({
|
"nMatched" : 0,
|
"nUpserted" : 0,
|
"nModified" : 0,
|
"writeError" : {
|
"code" : 16837,
|
"errmsg" : "cannot use the part (a of a.-2) to traverse the element ({a: [ 1.0, 2.0 ]})"
|
}
|
})
|
Attachments
Issue Links
- related to
-
SERVER-13318 Update stats are incorrect after an error
-
- Closed
-