1
我的文件看起來是這樣的:從MongoDB中的數組中移除一個原始元素?
{
_id: "57008339e7537f033b67cf84",
title: "my title",
urls: ["1.html", "2.html", "3.html"]
}
我想從urls
刪除"2.html"
。引用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' }