Partition data around a match query during aggregation
问题 What I have been trying to get my head around is to perform some kind of partitioning(split by predicate) in a mongo query. My current query looks like: db.posts.aggregate([ {"$match": { $and:[ {$or:[{"toggled":false},{"toggled":true, "status":"INACTIVE"}]} , {"updatedAt":{$gte:1549786260000}} ] }}, {"$unwind" :"$interests"}, {"$group" : {"_id": {"iid": "$interests", "pid":"$publisher"}, "count": {"$sum" : 1}}}, {"$project":{ _id: 0, "iid": "$_id.iid", "pid": "$_id.pid", "count": 1 }} ]) This