Skip to content

Instantly share code, notes, and snippets.

@vunguyen9404
Created May 31, 2023 17:09
Show Gist options
  • Select an option

  • Save vunguyen9404/d9b6a13a90de30c6db7ab40b0c49f217 to your computer and use it in GitHub Desktop.

Select an option

Save vunguyen9404/d9b6a13a90de30c6db7ab40b0c49f217 to your computer and use it in GitHub Desktop.
Wheel Statistics
db.getCollection("wheel_histories").aggregate(
[
{
"$match" : {
}
},
{
"$group" : {
"_id" : "$createdAtInt",
"totalGem" : {
"$sum" : "$receivedItem.value"
},
"totalSpin" : {
"$sum" : NumberInt(1)
},
"users" : {
"$addToSet" : "$user"
}
}
},
{
"$project" : {
"totalGem" : "$totalGem",
"date" : "$_id",
"totalUser" : {
"$size" : "$users"
},
"totalSpin" : "$totalSpin"
}
},
{
"$sort" : {
"date" : NumberInt(1)
}
}
],
{
"allowDiskUse" : false
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment