使用 find ObjectId 时不可迭代
Not iterable when using find ObjectId
我试图在我的 mongodb 中找到某个文档,然后使用查找查询更新它的 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] }
我试图在我的 mongodb 中找到某个文档,然后使用查找查询更新它的 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] }