Skip to content

Instantly share code, notes, and snippets.

@seryh
Created May 16, 2016 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seryh/90dff7c7d0b6d29c6344b6737734969d to your computer and use it in GitHub Desktop.
Save seryh/90dff7c7d0b6d29c6344b6737734969d to your computer and use it in GitHub Desktop.
[
{"$match": {
"date": {
"$gte":"2016-03-11 18:00:00",
"$lte":"2016-04-11 18:00:00"
},
"userID": 102}
},
{ "$project" : {"fDate":{"$add": ["$date", 21600000]}, "stats":1, "date": 1, "userID": 1}},
{
"$group": {
"_id": { "year": { "$year": "$fDate" }, "dayOfYear": { "$dayOfYear": "$fDate" }, "userID": "$userID" },
"userID" : { "$last": "$userID" },
"lastUpdate" : { "$last": "$date" },
"countOrder": {"$sum": "$stats.countOrder"},
"priceTotal": {"$sum": "$stats.priceTotal"},
"priceLostProfit": {"$sum": "$stats.priceLostProfit"},
"countCanceled": {"$sum": "$stats.countCanceled"},
"countCompleted": {"$sum": "$stats.countCompleted"}
}
},
{ "$project" : {
"_id": 0,
"userID": "$userID",
"lastUpdate": "$lastUpdate",
"stats": {
"countOrder": "$countOrder",
"priceTotal": "$priceTotal",
"priceLostProfit": "$priceLostProfit",
"countCanceled": "$countCanceled",
"countCompleted":"$countCompleted"
}} },
{ "$sort": { "lastUpdate" : 1 } }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment