I try to update multiple documents with mongoose (3.8.37), but no document is updated.
I've done all things, that I've learned from other questions (see below):
- Use a callback function
- Specify multi:true
My update statement:
Animal.where({ type: type}).update({deleted:1}, { multi: true, overwrite: true }, function (err,doc) { console.log("updates: "+doc); }); updates: 0
When I just count the documents, I'll get a result. => The query is correct
Animal.where({type: type}).count(function (err,doc) { console.log("count: "+doc); }); count: 299
When I omit the multi:true option, the first record is updated. => The update statement is correct, too
Animal.where({ type: type}).update({deleted:-1}, function (err,doc) { console.log("updates: "+doc); }); updates: 1
So where's the error?
There are several questions dealing with this topic. Unfortunately none of these solves my problem.
- how can i update multiple documents in mongoose
- Mongoose update multiple documents doesn't update anything
- Mongoose: how to update *all* persons matching a condition?
** UPDATE
I've added a log callback and discovered that no query to the mongodb is executed as long as the options (multi:true) are specified.
.update({deleted:1},...to.update({ $set: { deleted:1}},{multi: true}, function...