I have a document that has a nested array. I want to delete an item in the array by it’s key value. I’ve tried doing an update with:
array('$unset' => array('item.key' => 1))
array('$pull' => array('item.key' => 1))
Doing, $unset , kept the key but nulled out the value, I want to get rid of it entirely. Pull didn’t do anything.
Any suggestions?
Thank you!
In order to use
$pullyou have to specify the entire array element you want to delete, luckily$pullis special in that you can specify a match criteria for the element you are$pullingHere is an example:
This will delete array element where “key2” exists as a keyname regardless of the value.
Sounds like this is what you want.
Here is a reference.