exilonX
exilonX

Reputation: 1761

Mongoose update changes only one value

I want to update multiple values in mongo using mongoose, more accurate I want to update all the values that have a certain field smaller than a value and I am trying something like this:

    var conditions = {Number: {$lt : 6000}};
    var update = {$set: {closed_flag : true}};
    var options = {};

    UPUSTP.update(conditions, update, options, function(err, data) {
        if (err) {
             console.log(err.message);
             return;
        }
        console.log(data);
   });

If I try the same thing with an update I get 1000 values that were found but if I run update with the same conditions the last console.log outputs 1, so just one value was updated... I can figure out what the problem is...

Upvotes: 0

Views: 690

Answers (1)

throrin19
throrin19

Reputation: 18207

To update multiples items with mongodb, yout options object should like this :

{ multi : true }

This option will tell MongoDB to update ALL elements that satisfy the query

Upvotes: 2

Related Questions