[英]Node.js - MongoDB remove document doesn't work
I am trying to remove all documents from collection that have field called uuid
and the value $in
array
that I pass. 我试图删除集合有场名为所有文档
uuid
和价值$in
array
,我通过。 However, it doesn't work. 但是,它不起作用。 Here is the code and the output that I have so far.
这是我到目前为止的代码和输出。
Code: 码:
app.post("/deleteRetrievedOfflineMessages", function(req, res) {
console.log("req.query.uuids => " + req.query.uuids);
var uuids = [];
uuids.push(req.query.uuids);
console.log("uuids[] => " + uuids);
offlineMessages.remove({ uuid: { $in: uuids } }, function(err, result) {
if (!err) {
console.log("offlineMessages.remove => no err");
console.log("result => " + result);
res.json("success");
} else {
sendErrorEmail(err);
res.json("error");
}
});
});
Output: 输出:
req.query.uuids => b964ddaa52b24b6e9f06cc2d1269c064,e0262f6807b6445cb455ae99d90e0315,dc9760634f364bdaa963c46b9a95170b
uuids[] => b964ddaa52b24b6e9f06cc2d1269c064,e0262f6807b6445cb455ae99d90e0315,dc9760634f364bdaa963c46b9a95170b
offlineMessages.remove => no err
result => {"ok":1,"n":0}
您必须先将req.query.uuids拆分,然后再将其提供给$ in运算符。
const uuids = req.query.uuids.split(',');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.