Last active
January 28, 2019 17:03
-
-
Save Visrozar/a85eab46c438b7bb64dcf915d1f7bda8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.collection.aggregate([ | |
{ | |
"$project": { | |
"_id": 1, | |
"product": 1, | |
"day": { | |
"$dayOfMonth": "$time" | |
}, | |
"month": { | |
"$month": "$time" | |
}, | |
"year": { | |
"$year": "$time" | |
} | |
} | |
}, | |
{ | |
"$project": { | |
"_id": 1, | |
"product": 1, | |
"time": { | |
"$concat": [ | |
{ | |
"$substr": ["$year", 0, 4] | |
}, | |
"-", | |
{ | |
"$substr": ["$month", 0, 2] | |
}, | |
"-", | |
{ | |
"$substr": ["$day", 0, 2] | |
} | |
] | |
} | |
} | |
}, | |
{ | |
"$group": { | |
"_id": { | |
"time": "$time", | |
"product": "$product" | |
} | |
} | |
}, | |
{ | |
"$group": { | |
"_id": "$_id.time", | |
"count": { | |
"$sum": 1 | |
} | |
} | |
} | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment