Shaishab Roy
2016-07-21 06:53:55 UTC
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 :)
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/afcef1b4-30d8-48c3-9166-951846c6e2ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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 :)
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+***@googlegroups.com.
To post to this group, send email to mongodb-***@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/afcef1b4-30d8-48c3-9166-951846c6e2ff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.