1

I have a document

firm    {
    "_id" : 0,
    "users" : [
        { 
            "draft_items" : [
                {
                    "pkg" : "10",
                    "id" : 1
                },
                {
                    "pkg" : "10",
                    "id" : 2
                },
            ]
        }
    ]
}

I want to pull the element from draft items where id is 2

Here is the expected result:

{
    "_id" : 0,
    "users" : [
        { 
            "draft_items" : [
                {
                    "pkg" : "10",
                    "id" : 1
                }
            ]
        }
    ]
}

I followed this:MongoDB pull element from array two levels deep and tried

db.firm.update( { 'users.draft_items.id' : 2 },{ $pull: { "users.$.draft_items": {"id":2} } } ) 

But it did not work!

Community
  • 1
  • 1
Praveen Singh Yadav
  • 1,831
  • 4
  • 20
  • 31

0 Answers0