簡體   English   中英

我如何找到那些特定字段與任何其他文檔匹配(具有相同值)的文檔

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM