1

I am trying to remove an element from array:

{ "_id" : ObjectId("56728dac7e30ad640af52a88"), "key" : "inbox", "notify" : false, "unread" : [ "5" ], "user" : "admin" }

I tried with this query mgr.db.update_one({"key":"inbox","user":"admin"},{"$pull":{"unread.5":""}}) and also mgr.db.update_one({"key":"inbox","user":"admin"},{"$pull":{"unread":{"5":""}}), both does not remove the element from the array. How can I achieve this?

1 Answer 1

1

The $pull operator has the form:

{ $pull: { <field1>: <value|condition>, <field2>: <value|condition>, ... } }

Which means the correct query is:

mgr.db.collection.updateOne(
    { "key": "inbox", "user": "admin"},
    { "$pull": { "unread": "5" } }
)
Sign up to request clarification or add additional context in comments.

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.