1

My document looks like this:

{
    _id: "57008339e7537f033b67cf84",
    title: "my title",
    urls: ["1.html", "2.html", "3.html"]
}  

I want to remove "2.html" from urls. Referencing this question I have tried following code:

db.collection("bookmarks").update({_id: "57008339e7537f033b67cf84"}, {$pull: {"urls": {$eq: "2.html"}}}, (err, result) => {
    if (err) {
        console.log(err);
    }
});

But the output is:

{ [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' }
Community
  • 1
  • 1
Zen
  • 5,065
  • 8
  • 29
  • 49

1 Answers1

0

You don't need the $eq operator:

Just use {$pull: {"urls": "2.html"}}

db.collection("bookmarks").update({_id: "57008339e7537f033b67cf84"}, {$pull: {"urls": "2.html"}}, (err, result) => {
    if (err) {
        console.log(err);
    }
});

$pull documentation

michelem
  • 14,430
  • 5
  • 50
  • 66