it is required to process a data sample, and then make actions on one of the records in the sample
how to do it right?
via promise , callback or setTimeout
model.update( { groupId : groupId }, { field1 : val1, field2 : val2 } ) UPDATE
I tried several options, but either the second update works ahead of time
c promise
mongoose.Promise = global.Promise; model.update({ groupId: 5, order: {$gte: 0, $lt: 3} }, { $inc: { order: 1 } }, { multi: true }) .then(function(){ model.update({ id: 7 },{ order: 0 }); }); or with `callback '
model.update({ groupId: 5, order: {$gte: 0, $lt: 3} }, { $inc: { order: 1 } }, { multi: true }, function(er, o){ err && console.error(err); model.update({ id: 7 },{ order: 0 }); }); or changes do not occur at all
mongoose.Promise = global.Promise; model.find({ groupId: 5, order: {$gte: 0, $lt: 3} }) .exec() .then(function(ar){ for(var i = 0; i < ar.length; i++) { ar[i].order++; } return ar; }) .then(function(){ model.update({ id: 7 },{ order: 0 }); }); tell me what was done wrong?
return ar.save();most likely - vp_arthpromiseversion, we cannot useupdateinstead offind? or is there also a restriction due tothenables? - ravend