I m trying to completely remove a document from mongodb collection having an array of documents as property. I have used $pull and $unset , which successfully find and remove the values within a doc by making them null but the doc still exists.
Eg .Original document
{
_id: 6452725 gsjhye73636,
ItemsArray: [{
_id: 757264 gsjfgs685,
ItemName: "item1",
ItemValue: "value1"
},
{
_id: 757264 gsjfgs686,
ItemName: "item2",
ItemValue: "value2"
},
{
_id: 757264 gsjfgs687,
ItemName: "item3",
ItemValue: "value3"
}
],
OtherProp: "some value"
}
After applying $pull and $unset for removing item2 document.
{
_id: 6452725 gsjhye73636,
ItemsArray: [{
_id: 757264 gsjfgs685,
ItemName: "item1",
ItemValue: "value1"
},
{
_id: 757264 gsjfgs686,
ItemName: null,
ItemValue: null
},
{
_id: 757264 gsjfgs687,
ItemName: "item3",
ItemValue: "value3"
}
],
OtherProp: "some value"
}
What I want is this:
{
_id: 6452725 gsjhye73636,
ItemsArray: [{
_id: 757264 gsjfgs685,
ItemName: "item1",
ItemValue: "value1"
},
{
_id: 757264 gsjfgs687,
ItemName: "item3",
ItemValue: "value3"
}
],
OtherProp: "some value"
}