This is my example document:
{
keys: {
attr1: ['a', 'b', 'c'],
attr2: ['d', 'e']
}
}
I remove the items in the array like this...
{
$pullAll: {
'keys.attr2': ['d', 'e']
}
}
And this leaves me with an empty array for the attr2 field:
{
keys: {
attr1: ['a', 'b', 'c'],
attr2: []
}
}
But what I want to do is if the field is now an empty then I want $unset
that field so that the final result looks like this:
{
keys: {
attr1: ['a', 'b', 'c']
}
}
I want to do this within a single find and update operation.
Thanks for the help.