Using MongoDB $pull to delete documents within an Array

回眸只為那壹抹淺笑 提交于 2019-11-28 07:36:00

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.

Amit Kumar

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"} ]  } });
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!