我正在尝试在mongodb中找到某个文档,然后使用find查询更新它的int值,我使用了$ in,因为我使用了数组来查找其中的每个元素,但是当我使用ObjectId
时它给我错误:
bloodinventoryDocs is not iterable
这是我所做的
var mongoose = require('mongoose');
var id = mongoose.Types.ObjectId('5c014c999cc48c3b0057988b');
var newValue = 1;
var newBloodgroup = "A_positive";
var newGetbloodcomponent = "Whole Blood";
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');
}
});
}
});
只需使用chapter: { $in: [id] }