Node.js - MongoDB删除文档不起作用

时间:2017-12-21 18:36:13

标签: javascript node.js mongodb

我正在尝试从集合中删除所有已调用字段的文档 uuid以及我传递的值$in array。但是,它不起作用。这是我到目前为止的代码和输出。

代码:

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

输出:

req.query.uuids => b964ddaa52b24b6e9f06cc2d1269c064,e0262f6807b6445cb455ae99d90e0315,dc9760634f364bdaa963c46b9a95170b
uuids[] => b964ddaa52b24b6e9f06cc2d1269c064,e0262f6807b6445cb455ae99d90e0315,dc9760634f364bdaa963c46b9a95170b
offlineMessages.remove => no err
result => {"ok":1,"n":0}

1 个答案:

答案 0 :(得分:0)

你必须拆分req.query.uuids,然后再将它送到$ in运算符。

const uuids = req.query.uuids.split(',');