Roman
Roman

Reputation: 2175

Delete elements from two nested arrays in one document

I have the following document:

{
    "_id" : "2646953848367646922",
    "arr1" : [
        {
            "n" : 1,
            "name" : "2646953848367646922"
        },
        {
            "n" : 0.75,
            "name" : "7750833069621794130"
        }
    ],
    "arr2" : [
        {
            "n" : 1,
            "name" : "2646953848367646922"
        },
        {
            "n" : 0.75,
            "name" : "7750833069621794130"
        }
    ]
}

Can I delete elements from two nested arrays by using only one query?

Upvotes: 0

Views: 30

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 312149

Use $pull for that. In the shell:

db.test.update({_id: "2646953848367646922"}, {$pull: {
    arr1: {name: "7750833069621794130"},
    arr2: {name: "2646953848367646922"}
}})

Upvotes: 2

Related Questions