Currently I believe that update()
in Mongoose has some problems, see:
https://groups.google.com/forum/#%21topic/mongoose-orm/G8i9S7E8Erg
and https://groups.google.com/d/topic/mongoose-orm/K5pSHT4hJ_A/discussion.
但是,对更新的笔试:。 (根据《示范法》规定) 定义是:
Earlier Solution(Depreciated after mongoose 5+ version)
Model.update = function (query, doc, options, callback) { ... }
You need to pass the options inside an object, so your code would be:
Model.update = function ({}, {cid: }, {multi: true}, function(err) { ... });
New Solution
Model.updateMany = function (query, doc, callback) { ... }
Model.updateMany = function ({}, {cid: }, function(err) { ... });
I believe that Mongoose wraps your cid in a $set, so this is not the same as running that same update in the mongo shell. If you ran that in the shell then all documents would be replaced by one with a single cid:
.