For example I have this document:
db.test.save({
_id: 1,
list: [
{ key: "a" },
{ key: "b" },
{ key: "c" },
{ key: "d" },
{ key: "e" }
]
})
and I need remove to the second element from the list.
For now I do that in two steps. I first unset the second list element but the $unset
operator doesn't remove the element, it modifies it to null
, and after that I pull any nullable value from the list field:
db.test.update({_id: 1}, {$unset: {"list.2": 1}})
db.test.update({_id: 1}, {$pull: {list: null}})
Is there a solution to do that in one operation?