For let, not incrementing if there is a same item

2020-02-07 12:33发布

问题:

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'); 
                    }
                });
            }  
        });