-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: 2.2.25
-
Component/s: MongoDB 3.2, MongoDB 3.4
-
Environment:Any platform.
In docs for both methods:
https://docs.mongodb.com/manual/reference/method/db.collection.updateOne/
https://docs.mongodb.com/manual/reference/method/db.collection.updateMany/
you can see:
> Using the update() pattern of field: value for the update parameter throws an error.
This is example how mongo shell handles it:
> db.test.insertOne({_id: 'test', field1: 1, field2: 2}); { "acknowledged" : true, "insertedId" : "test" } > db.test.updateOne({_id: 'test'}, {}); 2017-03-24T00:18:27.129+0300 E QUERY [main] Error: the update operation document must contain at least one atomic operator : DBCollection.prototype.updateOne@src/mongo/shell/crud_api.js:519:1 @(shell):1:1 > db.test.updateOne({_id: 'test'}, {});
Then if you try to do updateOne using node driver it will not throw error:
var testCollection = db.collection('test'); testCollection.updateOne({_id: 'test'}, {});
and object will be updated and will be looking like this
{_id: 'test'}
other fields will be removed.
This is dangerous operation and if client code made it by mistake it can lead to big problems with data. So, I think updateOne and updateMany should follow reference and throw error in this case.