10
我有一个mongo支持的联系人数据库,我试图通过一堆不同的方式找到重复的条目。Mongo - 如何汇总,过滤和包含匹配文档中的数据数组?
例如,如果2个触点有它们标记为可能重复,同上,用于电子邮件等
我使用MongoDB的2.4.2在Debian与pyMongo和MongoEngine同一个电话号码。
我至今是发现和计数包含相同的电话号码记录最接近:
dbh.person_document.aggregate([
{'$unwind': '$phones'},
{'$group': {'_id': '$phones', 'count': {'$sum': 1}}},
{'$sort': SON([('count', -1), ('_id', -1)])}
])
# Results in
{u'ok': 1.0,
u'result': [{u'_id': {u'number': u'404-231-4444', u'showroom_id': 5}, u'count': 5},
{u'_id': {u'number': u'205-265-6666', u'showroom_id': 5}, u'count': 5},
{u'_id': {u'number': u'213-785-7777', u'showroom_id': 5}, u'count': 4},
{u'_id': {u'number': u'334-821-9999', u'showroom_id': 5}, u'count': 3}
]}
所以我可以说是重复的数字,但我不能为我的数字生活了解如何返回实际包含这些项目的文档数组!
我想看到这种回报数据为每个编号:
# The ObjectIDs of the documents that contained the duplicate phone numbers
{u'_id': {u'number': u'404-231-4444', u'showroom_id': 5},
u'ids': [ObjectId('51c67e322b2192121ec4d8f2'), ObjectId('51c67e312b2192121ec4d8f0')],
u'count': 2},
任何帮助,不胜感激!