Using a different versions of the same query have different results when updating a value in an array.
If the array key name is alphabetically after the key "loc" field in the query it does not update but insert a blank subdocument.
changing
{ "_id" : ObjectId("587fa5ed7bc1efc69f4763e3"), "loc" : [ NumberInt(1), NumberInt(1) ], "lac" : [ { "tankId" : ObjectId("587fa5f04f4efe9c42d0dc53")}]} { "_id" : ObjectId("587fa5ed7bc1efc69f4763e4"), "loc" : [ NumberInt(1), NumberInt(1) ], "lpc" : [ { "tankId" : ObjectId("587fa5f04f4efe9c42d0dc54")}]}
with:
db.testing.update({"lac.tankId": ObjectId("587fa5f04f4efe9c42d0dc53"), "loc.0": 1, "loc.1":1 }, {$set:{"lac.$.test":1}}) db.testing.update({"lpc.tankId": ObjectId("587fa5f04f4efe9c42d0dc54"), "loc.0": 1, "loc.1":1 }, {$set:{"lpc.$.test":1}})
should result in
{ "_id" : ObjectId("587fa5ed7bc1efc69f4763e3"), "loc" : [ NumberInt(1), NumberInt(1) ], "lac" : [ { "tankId" : ObjectId("587fa5f04f4efe9c42d0dc53"), test: 1}]} { "_id" : ObjectId("587fa5ed7bc1efc69f4763e4"), "loc" : [ NumberInt(1), NumberInt(1) ], "lpc" : [ { "tankId" : ObjectId("587fa5f04f4efe9c42d0dc54"), test: 1}]}
but ends up with:
{ "_id" : ObjectId("587fa5ed7bc1efc69f4763e3"), "loc" : [ NumberInt(1), NumberInt(1) ], "lac" : [ { "tankId" : ObjectId("587fa5f04f4efe9c42d0dc53"), test: 1}]} { "_id" : ObjectId("587fa5ed7bc1efc69f4763e4"), "loc" : [ NumberInt(1), NumberInt(1) ], "lpc" : [ { "tankId" : ObjectId("587fa5f04f4efe9c42d0dc54")}, {test: 1}]}
- is related to
-
SERVER-18500 Resolve ambiguity of positional projections with multiple implicit array traversal predicates in certain cases
- Backlog