Using MongoDB $pull to delete documents within an Array
This will delete multiple tweets
in a single query just pass an array to $in
:-
db.clusters.update({},
{$pull: {members: {$in: [ {tweetID: '5327010328645530500'},{"tweetID" : "2820402625046999289"} ] } } },
{multi: true});
The above method doesnt work in mongoose so for mongoose do:-
db.clusters.update({},
{$pull: {members:[ {tweetID: '5327010328645530500'},{"tweetID" : "2820402625046999289"} ] } });
That's exactly what the $pull
operator does, so in the shell you could use an update
like:
db.clusters.update({},
{$pull: {members: {tweetID: '5327010328645530500'}}},
{multi: true})
Set the multi
option so that every document is updated, not just the first one.