I'm trying to increment an item in my mongodb using find $in array, but when there is a same item in an array for example ['apple','apple']
it should increment twice but for my case, it only increment once, look at my code:
var newValue = 1;
var newSerialcode = req.body.serialCode;
var newBloodgroup = req.body.blood_group;
var newGetbloodcomponent = req.body.blood_component;
Bloodinventory.find({ blood_component : { $in : newGetbloodcomponent} ,blood_group: { $in :newBloodgroup},chapter: { $in: [id] }}, function(err, bloodinventoryDocs) {
for(let bloodinventory of bloodinventoryDocs) {
bloodinventory.num_stock = bloodinventory.num_stock + newValue ;
bloodinventory.save(function(err) {
if (err) {
console.log(err);
} else {
console.log('success');
}
});
}
});
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…