Is there a way to delete a specific element from an array within a collection, such as the one shown below:
{
"_id" : "Y9BBFa4c4vMiAkjbi",
"metadata" : {
"tags" : [
"Anything",
"Something",
"More"
]
}
}
For instance, in this scenario I am looking to remove the element 'Something' if it exists.
var tag = 'Something';
if (Collection.find({ 'metadata.tags': tag }).count()) {
Collection.update(
{ _id: id },
{ $pull: { 'metadata.tags': tag } }
);
}