Below is my code..
group = {
$group: {
"_id": {
"user_email": "$user_email",
"sender_email": "$sender_email"
},
"count": { "$sum": 1 }
}
};
Schema.aggregate(([group]),function(errors,results){
console.log(results);
});
my output value is:
[ { _id:
{ user_email: '123@gmail.com',
sender_email: '235@gmail.com' },
count: 5 },
{ _id:
{ user_email: '123m@gmail.com',
sender_email: '235@gmail.com' },
count: 16 },
{ _id:
{ user_email: '455@gmail.com',
sender_email: '785@gmail.com' },
count: 8 },
{ _id:
{ user_email: '123@gmail.com',
sender_email: '235@gmail.com' },
count: 4 } ]
The above record shows the individual poke count.. i need to know that how many user_email has poked sender_email.(an user_email can poke a sender_email for many times but if the sender_email is poked for many times by a user_email i need not want the count as 'many' but i need the count as 1,in the same way if the various users have poked the sender_email i do not want the count of how many times each user has poked sender_email but how many user_email has poked sender_email). I need a mongoDb query for it?
{ user_email: '123@gmail.com',
sender_email: '235@gmail.com' },
count: 5 }
123@gmail.com poked 235@gmail.com for 5 times but i need to know the count of how many individual sender_email has been poked by various user_email without passing any parameter?
Below is my collection:
{
"_id" : ObjectId("590182b3168e590182b315b2"),
"updatedAt" : ISODate("2017-04-27T12:37:03.385Z"),
"createdAt" : ISODate("2017-04-27T05:33:39.563Z"),
"user_email" : "123@gmail.com",
"sender_email" : "235@gmail.com",
"status" : 1,
"__v" : 0
}
{
"_id" : ObjectId("590182c4a182c4aaa2d21"),
"updatedAt" : ISODate("2017-04-27T12:37:03.385Z"),
"createdAt" : ISODate("2017-04-27T05:33:56.122Z"),
"user_email" : "123@gmail.com",
"sender_email" : "235@gmail.com",
"status" : 1,
"__v" : 0
}
{
"_id" : ObjectId("590184182c4a1821d98a028"),
"updatedAt" : ISODate("2017-04-27T12:37:03.385Z"),
"createdAt" : ISODate("2017-04-27T05:39:40.425Z"),
"user_email" : "561@gmail.com",
"sender_email" : "235@gmail.com",
"status" : 1,
"__v" : 0
}
group = {
$group: {
"_id": {
"user_email": "$user_email",
"sender_email": "$sender_email"
},
"_id": {
"sender_email": "$sender_email"
},
"count": { "$sum": 1 }
}
};
My output:
[ { _id: { sender_email: '123@gmail.com' },
count: 1 },
{ _id: { sender_email: '345@gmail.com' },
count: 4 } ]
I have changed my query with that i have got the required output.