Skip to content

Instantly share code, notes, and snippets.

@samparsky
Last active February 11, 2020 07:06
Show Gist options
  • Select an option

  • Save samparsky/f168b6abd2ffd9168eade45dcf71c60e to your computer and use it in GitHub Desktop.

Select an option

Save samparsky/f168b6abd2ffd9168eade45dcf71c60e to your computer and use it in GitHub Desktop.
EventAggregate with Channel lookup
[
{
"$lookup":{
"from":"channels",
"localField":"channelId",
"foreignField":"id",
"as":"channel"
}
},
{
"$addFields":{
"channel":{
"$arrayElemAt":[
"$channel",
0
]
}
}
},
{
"$addFields":{
"leader":{
"$arrayElemAt":[
"$channel.spec.validators",
0
]
},
"follower":{
"$arrayElemAt":[
"$channel.spec.validators",
1
]
}
}
},
{
"$addFields":{
"value":{
"$subtract":[
"$value",
{
"$multiply":[
"$value",
{
"$divide":[
{
"$add":[
{
"$toLong":"$leader.fee"
},
{
"$toLong":"$follower.fee"
}
]
},
{
"$toLong":"$channel.depositAmount"
}
]
}
]
}
]
}
}
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment