Possible bug - Update not updating the right index

34 views
Skip to first unread message

Shiv

unread,
Jan 12, 2018, 4:26:26 PM1/12/18
to mongodb-user

Mongo Version 3.2.6 and 3.6.0

Consider two below document 

db.col.insert({ b:[ { k: 0, v: 0 }, { k: 1, v: 0 } ], c: [0] });
db.col.insert({ b:[ { k: 0, v: 0 }, { k: 1, v: 0 } ], a: [0] });


Update query

db.col.update({"b.k": 1,"c": 0}, {'$set': {'b.$.v': 1}}); --  doesn't work - incorrectly updates the first document in array b

db.col.update({"b.k": 1,"a": 0}, {'$set': {'b.$.v': 1}}); -- works

Find after above updates

{ "b" : [ { "k" : 0, "v" : 1 }, { "k" : 1, "v" : 0 } ], "c" : [ 0 ] }
{ "b" : [ { "k" : 0, "v" : 0 }, { "k" : 1, "v" : 1 } ], "a" : [ 0 ] }






Message has been deleted

Shiv

unread,
Jan 22, 2018, 6:46:00 AM1/22/18
to mongodb-user
Can anyone verify the behavior ? Is it documented somewhere ? Please let me know if you need more details.
Reply all
Reply to author
Forward
0 new messages