MongoDB 5.0 no longer allows to update an exsisting document with empty one

Viewed 104

I am trying following query in MongoDB v5.0 db.test.insertOne({"test":"value"}) db.test.update({"test":"value"},{}) ... this throws an error saying "Uncaught MongoDriverError: Update document requires atomic operators" but earlier(MongoDB 4.4.2) this used to pass and update the document to empty. why this is no longer allowed ?

I have checked this below question, but this talks about $set,$unset operators and above query seemed to be working fine. Why does MongoDB no longer allow using $set and $unset with an empty document? . PSI the image stating the above issue :- Problem

1 Answers

It works fine, you made a mistake in your testing.

MongoDB Enterprise mongos>  db.test.insertOne({"test":"value"}) 
{
    "acknowledged" : true,
    "insertedId" : ObjectId("611e6ba92bf1d59775386625")
}
MongoDB Enterprise mongos> db.test.update({"test":"value"},{})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
MongoDB Enterprise mongos> db.test.find()
{ "_id" : ObjectId("611e6ba92bf1d59775386625") }
Related