I am trying to simulate update conflict at path error in MongoDB as shown here:
rs0:PRIMARY> db.test.find();
{ "_id" : ObjectId("64050396a27f4d08e8c3a0d4"), "a" : 10, "b" : 4444 }
{ "_id" : ObjectId("640504d3781e448660488d79"), "a" : 1000, "b" : 4444, "d" : 4444 }
rs0:PRIMARY> db.test.update({"a":1000},{$set:{"a":100}, $set:{"a":100}, $set:{"f":4444},$set:{"f.g":1000}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
rs0:PRIMARY> db.test.update({"a":1000},{$set:{"a":100}, $set:{"a":100}, $set:{"x":4444},$set:{"x.y":1000}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
I also tried this:
rs0:PRIMARY> db.test.update({"a":1000},{$set:{"a":100}, $set:{"a":900}, $set:{"a":10000}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
What am I missing. I am not getting that error.
steevej
(Steeve Juneau)
#2
Most likely because it is not the same updates.
In most implementation of JSON, only the last occurrence of repeated fields is kept.
So
is really equivalent to
{ '$set': { 'f.g': 1000 } }
and
is really
{ '$set': { 'x.y': 1000 } }
and finally
is really the same as
{ '$set': { a: 10000 } }
no conflict.
Try something like
db.test.updateOne( {} , { "$set" : { "a" : 1 } , "$unset" : { "a" : "" } } )
1 Like