in SQL, you can increment a field with one query

UPDATE myTable SET field = field + 1 

How to achieve the same in mongoose?

update I do this, but how do I add an increment there?

 var _id = 1, _field = 5; model.update({ id : _id }, { field : _field }); 

    1 answer 1

    Use the $ inc operator:

     model.update({ groupId : gid }, {$inc: {field:1}}, {multi: true}); 
    • Your example for some reason only updates the 1st entry, how to implement it for several lines? PS I search not by id, but by groupId - ravend
    • My example has nothing to do with it, it is taken from yours. Need multi option - vp_arth
    • thanks, earned - ravend