1

How do I remove all null elements in the data array - which is nested in the group array?

{
    "_id" : "wLXDvjDvbsxzfxabR",
    "group" : [
        {
            "title" : "title 1",
            "data" : [
                {
                    "note" : "text"
                },
                null
            ]
        },
        {
            "title" : "title 2",
            "data" : [
                {
                    "note 1" : "text"
                },
                {
                    "note 2" : "text"
                },
                null,
                {
                    "note 3" : "text"
                },
                null
            ]
        }
    ]
}

So in this example three null elements should be removed...

This gives me an 409-error:

Collection.update(
    { _id: 'wLXDvjDvbsxzfxabR' }, 
    { $pull: { "group.$.data": null } }
);
user3142695
  • 15,844
  • 47
  • 176
  • 332
  • Possible dublicate of http://stackoverflow.com/questions/5228210/how-to-remove-an-element-from-a-doubly-nested-array-in-a-mongodb-document – Volodymyr Synytskyi Jan 08 '16 at 23:33
  • Possible duplicate of [How can I pull sub-documents from an array?](http://stackoverflow.com/questions/34564195/how-can-i-pull-sub-documents-from-an-array) – styvane Jan 09 '16 at 08:52

0 Answers0