![](/img/trans.png)
[英]In MongoDB, how can I find documents whose id are in a array field of other documents?
[英]How do i find those documents whose particular fields matches with any other documents(have the same value)
{
_id: "010",
"email": "abc@gmail.com"
}
{
_id: "011",
"email": "abc@gmail.com"
}
例如上面的兩個文檔具有相同的 email id
試試這個
db.getCollection('collectionName').aggregate([{ $group: {
_id: { name: "$email" },
Ids: { $addToSet: "$_id" },
count: { $sum: 1 }
} }, {$match:{count:{$gte:2}}}]);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.