我有像
这样的文件{"title":"title_1","website":"website_1","isEdited":"true"},
{"title":"title_2","website":"website_1","isEdited":"true"},
{"title":"title_3","website":"website_2"},
{"title":"title_4","website":"website_3","isEdited":"false"}
所以文件有" isEdited"具有多个值的字段(None,true,flase)我想计算它们的所有出现次数并将它们分组为
{'_id' : '$website','edited_count': '?', 'not_edited_count': '?'}
而不是上面我能够得到这个
{u' isEditedCount':2,你' _id':你' website_1'}
使用此管道
[
{"$match": {"isEdited": 'true'}},
{"$group": {"_id": "$website", "isEditedCount": {"$sum": 1}}}
]
和 [ {u' isNotEditedCount':1,你' _id':u' website_2'}, {u' isNotEditedCount':1,你' _id':你' website_3'} ]
使用此管道
[
{"$match":{"$or":[{"isEdited": None},{"isEdited": 'false'}]}},
{"$group":{"_id": "$website","isNotEditedCount": {"$sum": 1}}}
]
我想将两个管道合并为一个