I have documents like this:
{
"_id" : ObjectId("565e906bc2209d91c4357b59"),
"userEmail" : "abc@example.com",
"subscription" : {
"project1" : {
"subscribed" : false
},
"project2" : {
"subscribed" : true
}
}
}
{
"_id" : ObjectId("565e906bc2209d91c4357b59"),
"userEmail" : "mno@example.com",
"subscription" : {
"project1" : {
"subscribed" : true
},
"project2" : {
"subscribed" : true
},
"project3" : {
"subscribed" : true
}
}
}
I would like to group by users with the list of projects where the subscribed
flag is set to true
.
For instance, what I'm expecting is:
abc@example.com - project2
mno@example.com - project1,project2,project3
I'll have a cron job which will send the respective details on the subscribed projects to the corresponding mail ids.
I tried aggregation, but aggregation needs the key specified. In my case the key (which is Project1, Project2 and so on) is dynamic. So I read somewhere mapReduce
is the correct option to go for. But I don't have an experience in using mapReduce
.
Kindly help me to solve this problem and make me to understand with more explanation on how to handle this.