1

I have the following document structure. I'm trying to remove components from the components array with $pull. I can't work out how to select "mast" or "commsbox" from the following document.

{
    "_id" : ObjectId("23456yujbvfdfg"),
    "d": 1234567,
    "components" : [
        [
            "mast",
            {
                "foo":"bar"
            }
        ],
        [
            "commsbox",
            {
                "BLARN": "bAAA"
            }
        ]
    ]
}

I've tried

db.sites.update({components: {$exists: true}, {$pull: { components.mast: {$exists: true} } }  }).pretty();

but I'm not able to select the component correctly.

1 Answer 1

1

You need to use $ operator to $pull from nested array

db.sites.update(
  { "components": { "$exists": true }},
  { "$pull": { "components.$": "mast" }}
)
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.