I'm aware of the $addToSet method for MongoDB, but I can't find a "remove" equivalent anywhere in the docs.
What's the best way to achieve this? Trying to achieve something like the following:
obj = {
name: 'object1',
tags: ['fus', 'ro', 'dah']
}
db.collection.update({
name: 'object1'
}, {
$removeFromSet: {
tags: 'dah'
}
});
I think you are looking for $pull, which "removes all instances of a value from an existing array".
db.collection.update(
{name: 'object1'},
{$pull: { tags: 'dah'}});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With