Updating several documents by the set identifier. Mongoose

I wonder if mongoose has some method of updating multiple id set documents. For example:

for (var i = 0, l = ids.length; i < l; i++) { Element.update({'_id': ids[i]}, {'visibility': visibility} ,function(err, records){ if (err) { return false; } else { return true; }; }); }; 

What I want to know if a mongoose can do something like this:

 Element.update({'_id': ids}, {'visibility': visibility}, {multi: true} ,function(err, records){ if (err) { return false; } }); 

where ids is an array of identifiers, for example ['id1', 'id2', 'id3'] is an array of patterns. The same question for the search.

+15
mongodb mongoose
Nov 20 '13 at 13:08
source share
1 answer

Probably yes. And it is called using the $ in operator in the mongodb request for update.

 db.Element.update( { _id: { $in: ['id1', 'id2', 'id3'] } }, { $set: { visibility : yourvisibility } } ) 

All you need to do is find how to implement $ in in mongoose.

+38
Nov 20 '13 at 13:47
source share



All Articles