Created
February 2, 2018 09:21
-
-
Save dglowinski/80feed0e8d51ec81040c143ab825967d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Account.aggregate([ | |
{$unwind: {path: "$tokens"}}, | |
{$match:{ "tokens.tokenId": tokenId }}, | |
{$project: { | |
address: 1, | |
balance:{ | |
$reduce: { | |
input: "$tokens.transactions", | |
initialValue: 0, | |
in: { $add:["$$value", "$$this.amount" ]} | |
} | |
}}}, | |
{$group: { | |
_id: 0, | |
count: { | |
$sum: 1 | |
}, | |
document: { | |
$push: "$$ROOT" | |
} | |
}}, | |
{$unwind: "$document"}, | |
{$sort: {"document.balance": -1}}, | |
{$skip: (page-1)*limit}, | |
{$limit: limit} | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment