Reputation: 3292
I have an array like below for multiple documents.
meta: [1, null]
I want to get rid of the null
value. So the array just looks like
meta: [1]
I tried with $unset
.updateMany({}, { $unset: { 'meta.1': 1 } }, { multi: true });
However, it doesn't remove null
value. How can I keep the value 1
but just take off null
from the array?
Upvotes: 1
Views: 430
Reputation: 36104
Try $pull to remove element from array, and updateMany()
not require multi: true
option,
.updateMany(
{ meta: null },
{ $pull: { meta: null } }
)
Upvotes: 1