Open wangming1993 opened 8 years ago
_member_ 的结构如下:
db.member.insert( { "name": "mike5", "socials": [ { "channel": "123", "openId": "12" }, { "channel": "124", "openId": "12" } ], } );
查找出member中socials中channel和openId重复的数据
db.member.aggregate( [ { "$match": { "socials": { "$elemMatch": { "channel": "123" } } } }, { "$unwind": "$socials" }, { "$group": { "_id":{ "channel": "$socials.channel", "openId": "$socials.openId" }, "count": { "$sum": 1 } } }, { "$match": { "count": { "$gt": 1 } } } ] );
_member_ 的结构如下:
查询要求
查找出member中socials中channel和openId重复的数据