我如何在mongo集合中找到重复的字段.
我想检查是否有任何"名称"字段是重复的.
{
"name" : "ksqn291",
"__v" : 0,
"_id" : ObjectId("540f346c3e7fc1054ffa7086"),
"channel" : "Sales"
}
Run Code Online (Sandbox Code Playgroud)
非常感谢!
我在mongodb中有大约170万份文件(将来10m +).其中一些代表我不想要的重复条目.文档的结构是这样的:
{
_id: 14124412,
nodes: [
12345,
54321
],
name: "Some beauty"
}
Run Code Online (Sandbox Code Playgroud)
如果文档至少有一个节点与具有相同名称的另一个文档相同,则文档是重复的.删除重复项的最快方法是什么?
我有一个包含如下文档的集合:
{
"_id" : ObjectId("55b377cb66b393427367c3e2"),
"comment" : "This is a comment",
"url_key" : "55b377cb66b393427367c3df", //This is an ObjectId from another record in a different collection
}
Run Code Online (Sandbox Code Playgroud)
我需要在此集合中找到包含注释和url_key重复值的记录。
我可以轻松地生成(使用汇总)相同,单个键(例如:注释)的重复记录,但是我不知道如何对多个关键字进行分组/汇总。
这是我当前的聚合管道:
db.comments.aggregate([ { $group: { _id: { comment: "$comment" }, uniqueIds: { $addToSet: "$_id" }, count: { $sum: 1 } } }, { $match: { count: { $gte: 2 } } }, { $sort: { count : -1} }, {$limit 10 } ]);
Run Code Online (Sandbox Code Playgroud) mongodb mongodb-query aggregation-framework mongodb-aggregation