我的文档如下:
{
_id: "57008339e7537f033b67cf84",
title: "my title",
urls: ["1.html", "2.html", "3.html"]
}
我想从"2.html"
中移除urls
。引用this question我尝试过以下代码:
db.collection("bookmarks").update({_id: "57008339e7537f033b67cf84"}, {$pull: {"urls": {$eq: "2.html"}}}, (err, result) => {
if (err) {
console.log(err);
}
});
但输出是:
{ [MongoError: unknown top level operator: $eq]
name: 'MongoError',
message: 'unknown top level operator: $eq',
driver: true,
index: 0,
code: 2,
errmsg: 'unknown top level operator: $eq' }
答案 0 :(得分:0)
您不需要$eq
运营商:
只需使用{$pull: {"urls": "2.html"}}
db.collection("bookmarks").update({_id: "57008339e7537f033b67cf84"}, {$pull: {"urls": "2.html"}}, (err, result) => {
if (err) {
console.log(err);
}
});
$pull
文档