Files
salvato.newfreeplanet/query_gruppi.js
Paolo Arena f625278801 ver "0.5.8"
Lista movimenti in formato Tabella
2022-09-16 19:38:57 +02:00

120 lines
2.1 KiB
JavaScript

db.getCollection('movements').aggregate(
[
{
"$match": {
"idapp": "13",
"$or": [
{
"accountFromId": 1
},
{
"accountToId": 1
}
]
}
},
{
"$lookup": {
"from": "accounts",
"localField": "accountFromId",
"foreignField": "_id",
"as": "accfrom"
}
},
{
"$lookup": {
"from": "accounts",
"localField": "accountToId",
"foreignField": "_id",
"as": "accto"
}
},
{
"$unwind": "$accfrom"
},
{
"$unwind": "$accto"
},
{
"$lookup": {
"from": "users",
"let": {
"username": "$accfrom.username",
"idapp": "$accfrom.idapp"
},
"pipeline": [
{
"$match": {
"$expr": {
"$and": [
{
"$eq": [
"$$username",
"$username"
]
},
{
"$eq": [
"$$idapp",
"$idapp"
]
}
]
}
}
}
],
"as": "userfrom"
}
},
{
"$unwind": "$userfrom"
},
{
"$lookup": {
"from": "users",
"let": {
"username": "$accto.username",
"idapp": "$accto.idapp"
},
"pipeline": [
{
"$match": {
"$expr": {
"$and": [
{
"$eq": [
"$$username",
"$username"
]
},
{
"$eq": [
"$$idapp",
"$idapp"
]
}
]
}
}
}
],
"as": "userto"
}
},
{
"$unwind": "$userto"
},
{
"$project": {
"transactionDate": 1,
"amount": 1,
"causal": 1,
"userfrom.username": 1,
"userfrom.profile.img": 1,
"userto.username": 1,
"userto.profile.img": 1
}
}
])