I have a member collection and find members by specific conditions and after get members I need to do some calculation for each member. To calculate need query on the same collection.
My process is
var members = db.collection('member').find({ createdDate: currentDate, country: 'BD'}).toArray();
members.forEach(function(doc) {
var result = db.collection('member').aggregate([
{ $match: { memberType: doc.memberType, country : doc.country } },
{
$group: {
_id: {memberType:"$memberType",country:"$country"},
memberCount: { $sum: {$cond:[{$gt: ["$numberOfInvitees",0]},1,0]} },
sameCount: { $sum: {$cond:[{$eq: ["$numberOfInvitees",doc.numberOfInvitees]},1,0]} }
}
}
]).toArray();
});
**My question is how can I do this using single aggregate query?**
can any one help me pls :)