I have documents with the following structure in my database:
{
"reading_ts": ISODate(...),
"points": 2.3,
"user_id": 2
}
I will have more documents like this for each user_id per day...millions of them... I would like to implement the following aggregation:
- Get the data for one month
- Group the data for each user_id
- Group the data for each day (so I will have the data for each day, for each user_id)
- Get the max 'points' for each user for each day
- Count how many users has the max points under value 10, how many between 10 and 20 and how many over 20
I can do the step 1 with a $match I can do the step 3 using this:
{
"$group": {
"_id": {
"$subtract": [
"$reading_ts",
{
"$mod": [
{
"$toLong": "$reading_ts"
},
(1000 * 60 * 60 * 24)
]
}
]
}
}
}
The problem is that I don't know how to merge the steps 2 and 3 for now.