1

Hi I've got such kind of structure. here is an example

{
    "_id" : "423dswar23ew2355",
    "competitions" : [ 
        "24",
        "58", 
        "354",
        "361"
    ],
}

How I can delete for example "58" item from "competitions" array.

I've seen some kind of solution like

{ $pull: { competitions: { $eq: "58" }}}

But my mongo says thar

MongoError: unknown top level operator: $eq

So can anybody come up with some more simple but at the same time working solution. Thanks in advance

3 Answers 3

1

Try following code:

db.col.update({_id: "423dswar23ew2355"}, { $pull: { "competitions": "58" } })

Remember that since you have strings you should pass "58" as a string.

Sign up to request clarification or add additional context in comments.

Comments

1

This should work for the new versions:

db.col.updateOne({_id: "423dswar23ew2355"}, { $pull: { "competitions": "58" } })

Comments

0

if you want to delete the 58, you can use

db.lists.update({}, {$unset : {"competitions.2" : 1 }})

then

db.lists.update({}, {$pull : {"competitions" : null}})

hope it could help you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.