我有一个集合,其中我仅采用_id:
const query = {status: "init"};
const project = {_id:1};
db.collection("mycoll")
.find(query)
.project(project)
.sort(sort)
.limit(limit)
.toArray(function (err, result) {
if (err) throw err;
update_coll(result);
res.send(result);
});
with console.dir(result)
[ { _id: ObjectID { _bsontype: 'ObjectID', id: [Object] } },
{ _id: ObjectID { _bsontype: 'ObjectID', id: [Object] } },
{ _id: ObjectID { _bsontype: 'ObjectID', id: [Object] } },
{ _id: ObjectID { _bsontype: 'ObjectID', id: [Object] } },
{ _id: ObjectID { _bsontype: 'ObjectID', id: [Object] } },
{ _id: ObjectID { _bsontype: 'ObjectID', id: [Object] } },
{ _id: ObjectID { _bsontype: 'ObjectID', id: [Object] } },
{ _id: ObjectID { _bsontype: 'ObjectID', id: [Object] } } ]
现在我想像这样进行一次原子更新
db.collection("mycoll").update(
{_id: {$in:[pending_array_whitelist]}},
{
$set: {
status: "pending"
}
},
{multi:true},
(error, result) => {
if (error) return console.log(error);
}
);
但是我的代码不起作用,我没有任何更新。
如果我在shell中执行相同的查询,则可以正常工作