fixed: La modalità Tabella non funziona più ! (non si vede la lista dei movimenti)
This commit is contained in:
32
mongodb/Esempio.mongodb
Normal file
32
mongodb/Esempio.mongodb
Normal file
@@ -0,0 +1,32 @@
|
||||
use('test_FreePlanet');
|
||||
|
||||
let passo1 = [
|
||||
|
||||
]
|
||||
|
||||
let passo2 = [
|
||||
|
||||
]
|
||||
|
||||
let passo2b = [
|
||||
];
|
||||
|
||||
|
||||
let passo3 = [
|
||||
];
|
||||
|
||||
|
||||
let aggregation = [];
|
||||
|
||||
let test = false;
|
||||
|
||||
if (test) {
|
||||
aggregation = [...aggregation, ...passo4];
|
||||
} else {
|
||||
aggregation = [...aggregation, ...passo1];
|
||||
aggregation = [...aggregation, ...passo2];
|
||||
aggregation = [...aggregation, ...passo2b];
|
||||
aggregation = [...aggregation, ...passo3];
|
||||
}
|
||||
|
||||
db.users.aggregate(aggregation);
|
||||
280
mongodb/Paolo.mongodb
Normal file
280
mongodb/Paolo.mongodb
Normal file
@@ -0,0 +1,280 @@
|
||||
// MongoDB Playground
|
||||
// To disable this template go to Settings | MongoDB | Use Default Template For Playground.
|
||||
// Make sure you are connected to enable completions and to be able to run a playground.
|
||||
// Use Ctrl+Space inside a snippet or a string literal to trigger completions.
|
||||
|
||||
// Select the database to use.
|
||||
use('test_FreePlanet');
|
||||
|
||||
|
||||
let passo1 = [
|
||||
{
|
||||
$match: {
|
||||
idapp: "13",
|
||||
"profile.mycircuits": {
|
||||
$elemMatch: {
|
||||
circuitname: {
|
||||
$eq: "RISO Viterbo",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "circuits",
|
||||
as: "circuit",
|
||||
let: {
|
||||
circuitname: "RISO Viterbo",
|
||||
idapp: "$idapp",
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{
|
||||
$eq: [
|
||||
"$name",
|
||||
"$$circuitname",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$idapp",
|
||||
"$$idapp",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$circuit",
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
username: 1,
|
||||
profile: 1,
|
||||
idapp: 1,
|
||||
"circuit.name": 1,
|
||||
"circuit._id": 1,
|
||||
"circuit.refused_users": 1,
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
let passo2 = [
|
||||
{
|
||||
$lookup: {
|
||||
from: "accounts",
|
||||
as: "account",
|
||||
let: {
|
||||
username: "$username",
|
||||
idapp: "$idapp",
|
||||
circuitId: "$circuit._id",
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{
|
||||
$eq: [
|
||||
"$$username",
|
||||
"$username",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$$idapp",
|
||||
"$idapp",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$$circuitId",
|
||||
"$circuitId",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
let passo2b = [
|
||||
{
|
||||
$unwind: "$account",
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
let passo3 = [
|
||||
{
|
||||
$match: {
|
||||
idapp: "13",
|
||||
},
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
desc: 1,
|
||||
},
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
let passo3b = [
|
||||
{
|
||||
$unwind: "$circuit",
|
||||
},
|
||||
]
|
||||
|
||||
let passo3c = [
|
||||
{
|
||||
$lookup: {
|
||||
from: "circuit.refused_users",
|
||||
as: "myris",
|
||||
let: {
|
||||
username: "$username",
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{
|
||||
$eq: [
|
||||
"$$username",
|
||||
"$username",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
let passo3cOFF = [
|
||||
{
|
||||
$match: {
|
||||
"circuit.refused_users": {
|
||||
$elemMatch: {
|
||||
username: {
|
||||
$eq: "Emilie",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
let passo4 = [
|
||||
{
|
||||
$lookup: {
|
||||
from: "users",
|
||||
localField: "refused_users.username",
|
||||
foreignField: "username",
|
||||
as: "user",
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
"user.idapp": 1,
|
||||
"user.username": 1,
|
||||
"user.profile.img": 1,
|
||||
"user.profile.qualifica": 1,
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
let passo4b = [
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: {
|
||||
$mergeObjects: [
|
||||
{
|
||||
$arrayElemAt: [
|
||||
"$user",
|
||||
0,
|
||||
],
|
||||
},
|
||||
"$$ROOT",
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
let passo4c = [
|
||||
|
||||
{
|
||||
$unwind: "$user",
|
||||
},
|
||||
{
|
||||
$replaceRoot: {
|
||||
newRoot: "$user",
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
let passo5 = [
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
count: {
|
||||
$sum: 1,
|
||||
},
|
||||
results: {
|
||||
$push: "$$ROOT",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
count: 1,
|
||||
rows: {
|
||||
$slice: [
|
||||
"$results",
|
||||
0,
|
||||
10,
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
let aggregation = [];
|
||||
|
||||
let test = false;
|
||||
|
||||
if (test) {
|
||||
aggregation = [...aggregation, ...passo4];
|
||||
} else {
|
||||
aggregation = [...aggregation, ...passo1];
|
||||
aggregation = [...aggregation, ...passo2];
|
||||
aggregation = [...aggregation, ...passo2b];
|
||||
aggregation = [...aggregation, ...passo3];
|
||||
aggregation = [...aggregation, ...passo3b];
|
||||
aggregation = [...aggregation, ...passo3c];
|
||||
// aggregation = [...aggregation, ...passo4];
|
||||
aggregation = [...aggregation, ...passo4b];
|
||||
// aggregation = [...aggregation, ...passo4c];
|
||||
// aggregation = [...aggregation, ...passo5];
|
||||
}
|
||||
|
||||
// Run the aggregation and open a cursor to the results.
|
||||
// Use toArray() to exhaust the cursor to return the whole result set.
|
||||
// You can use hasNext()/next() to iterate through the cursor page by page.
|
||||
db.users.aggregate(aggregation);
|
||||
199
mongodb/TabellaMovSchedeOK.mongodb
Normal file
199
mongodb/TabellaMovSchedeOK.mongodb
Normal file
@@ -0,0 +1,199 @@
|
||||
use('test_FreePlanet');
|
||||
|
||||
let passo1 = [
|
||||
|
||||
{
|
||||
$sort: {
|
||||
transactionDate: -1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
idapp: "13",
|
||||
$or: [
|
||||
{
|
||||
accountFromId: "632b300002f403d67895d79c",
|
||||
},
|
||||
{
|
||||
accountToId: "632b300002f403d67895d79c",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "accounts",
|
||||
localField: "accountFromId",
|
||||
foreignField: "_id",
|
||||
as: "accfrom",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$accfrom",
|
||||
},
|
||||
{
|
||||
$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: "accounts",
|
||||
localField: "accountToId",
|
||||
foreignField: "_id",
|
||||
as: "accto",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$accto",
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "circuits",
|
||||
localField: "accfrom.circuitId",
|
||||
foreignField: "_id",
|
||||
as: "circuitfrom",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$circuitfrom",
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "circuits",
|
||||
localField: "accto.circuitId",
|
||||
foreignField: "_id",
|
||||
as: "circuitto",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$circuitto",
|
||||
},
|
||||
{
|
||||
$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,
|
||||
notifId: 1,
|
||||
"circuitfrom.symbol": 1,
|
||||
"circuitto.symbol": 1,
|
||||
"userfrom.username": 1,
|
||||
"userfrom.profile.img": 1,
|
||||
"userto.username": 1,
|
||||
"userto.profile.img": 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
count: {
|
||||
$sum: 1,
|
||||
},
|
||||
results: {
|
||||
$push: "$$ROOT",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
count: 1,
|
||||
rows: {
|
||||
$slice: [
|
||||
"$results",
|
||||
0,
|
||||
20,
|
||||
],
|
||||
},
|
||||
},
|
||||
}
|
||||
];
|
||||
|
||||
let passo2 = [];
|
||||
|
||||
let passo2b = [
|
||||
];
|
||||
|
||||
|
||||
let passo3 = [
|
||||
];
|
||||
|
||||
|
||||
let aggregation = [];
|
||||
|
||||
let test = false;
|
||||
|
||||
if (test) {
|
||||
aggregation = [...aggregation, ...passo4];
|
||||
} else {
|
||||
aggregation = [...aggregation, ...passo1];
|
||||
aggregation = [...aggregation, ...passo2];
|
||||
aggregation = [...aggregation, ...passo2b];
|
||||
aggregation = [...aggregation, ...passo3];
|
||||
}
|
||||
|
||||
db.movements.aggregate(aggregation);
|
||||
570
mongodb/TabellaMovimenti.mongodb
Normal file
570
mongodb/TabellaMovimenti.mongodb
Normal file
@@ -0,0 +1,570 @@
|
||||
use('test_FreePlanet');
|
||||
|
||||
let orig =
|
||||
[
|
||||
{
|
||||
$match: {
|
||||
idapp: "13",
|
||||
"profile.mycircuits": {
|
||||
$elemMatch: {
|
||||
circuitname: {
|
||||
$eq: "RISO Test",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "circuits",
|
||||
as: "circuit",
|
||||
let: {
|
||||
circuitname: "RISO Test",
|
||||
idapp: "$idapp",
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{
|
||||
$eq: [
|
||||
"$name",
|
||||
"$$circuitname",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$idapp",
|
||||
"$$idapp",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$circuit",
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
username: 1,
|
||||
profile: 1,
|
||||
idapp: 1,
|
||||
"circuit.name": 1,
|
||||
"circuit._id": 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "accounts",
|
||||
as: "account",
|
||||
let: {
|
||||
username: "$username",
|
||||
idapp: "$idapp",
|
||||
circuitId: "$circuit._id",
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{
|
||||
$eq: [
|
||||
"$$username",
|
||||
"$username",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$$idapp",
|
||||
"$idapp",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$$circuitId",
|
||||
"$circuitId",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$account",
|
||||
},
|
||||
{
|
||||
$sort: {
|
||||
transactionDate: -1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
idapp: "13",
|
||||
$or: [
|
||||
{
|
||||
accountFromId: "632b300002f403d67895d79c",
|
||||
},
|
||||
{
|
||||
accountToId: "632b300002f403d67895d79c",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "accounts",
|
||||
localField: "accountFromId",
|
||||
foreignField: "_id",
|
||||
as: "accfrom",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$accfrom",
|
||||
},
|
||||
{
|
||||
$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: "accounts",
|
||||
localField: "accountToId",
|
||||
foreignField: "_id",
|
||||
as: "accto",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$accto",
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "circuits",
|
||||
localField: "accfrom.circuitId",
|
||||
foreignField: "_id",
|
||||
as: "circuitfrom",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$circuitfrom",
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "circuits",
|
||||
localField: "accto.circuitId",
|
||||
foreignField: "_id",
|
||||
as: "circuitto",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$circuitto",
|
||||
},
|
||||
{
|
||||
$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,
|
||||
notifId: 1,
|
||||
"circuitfrom.symbol": 1,
|
||||
"circuitto.symbol": 1,
|
||||
"userfrom.username": 1,
|
||||
"userfrom.profile.img": 1,
|
||||
"userto.username": 1,
|
||||
"userto.profile.img": 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
count: {
|
||||
$sum: 1,
|
||||
},
|
||||
results: {
|
||||
$push: "$$ROOT",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
count: 1,
|
||||
rows: {
|
||||
$slice: [
|
||||
"$results",
|
||||
-20,
|
||||
20,
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
let passo1 =
|
||||
[
|
||||
{
|
||||
$match: {
|
||||
idapp: "13",
|
||||
"profile.mycircuits": {
|
||||
$elemMatch: {
|
||||
circuitname: {
|
||||
$eq: "RISO Test",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "circuits",
|
||||
as: "circuit",
|
||||
let: {
|
||||
circuitname: "RISO Test",
|
||||
idapp: "$idapp",
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{
|
||||
$eq: [
|
||||
"$name",
|
||||
"$$circuitname",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$idapp",
|
||||
"$$idapp",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$circuit",
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
username: 1,
|
||||
profile: 1,
|
||||
idapp: 1,
|
||||
"circuit.name": 1,
|
||||
"circuit._id": 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "accounts",
|
||||
as: "account",
|
||||
let: {
|
||||
username: "$username",
|
||||
idapp: "$idapp",
|
||||
circuitId: "$circuit._id",
|
||||
},
|
||||
pipeline: [
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$and: [
|
||||
{
|
||||
$eq: [
|
||||
"$$username",
|
||||
"$username",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$$idapp",
|
||||
"$idapp",
|
||||
],
|
||||
},
|
||||
{
|
||||
$eq: [
|
||||
"$$circuitId",
|
||||
"$circuitId",
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$account",
|
||||
},
|
||||
|
||||
]
|
||||
let passo2 = [
|
||||
{
|
||||
$sort: {
|
||||
transactionDate: -1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
idapp: "13",
|
||||
$or: [
|
||||
{
|
||||
accountFromId: "632b300002f403d67895d79c",
|
||||
},
|
||||
{
|
||||
accountToId: "632b300002f403d67895d79c",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "accounts",
|
||||
localField: "accountFromId",
|
||||
foreignField: "_id",
|
||||
as: "accfrom",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$accfrom",
|
||||
},
|
||||
{
|
||||
$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: "accounts",
|
||||
localField: "accountToId",
|
||||
foreignField: "_id",
|
||||
as: "accto",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$accto",
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "circuits",
|
||||
localField: "accfrom.circuitId",
|
||||
foreignField: "_id",
|
||||
as: "circuitfrom",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$circuitfrom",
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: "circuits",
|
||||
localField: "accto.circuitId",
|
||||
foreignField: "_id",
|
||||
as: "circuitto",
|
||||
},
|
||||
},
|
||||
{
|
||||
$unwind: "$circuitto",
|
||||
},
|
||||
{
|
||||
$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,
|
||||
notifId: 1,
|
||||
"circuitfrom.symbol": 1,
|
||||
"circuitto.symbol": 1,
|
||||
"userfrom.username": 1,
|
||||
"userfrom.profile.img": 1,
|
||||
"userto.username": 1,
|
||||
"userto.profile.img": 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: null,
|
||||
count: {
|
||||
$sum: 1,
|
||||
},
|
||||
results: {
|
||||
$push: "$$ROOT",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
count: 1,
|
||||
rows: {
|
||||
$slice: [
|
||||
"$results",
|
||||
-20,
|
||||
20,
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
;
|
||||
|
||||
let passo2b = [
|
||||
];
|
||||
|
||||
|
||||
let passo3 = [
|
||||
];
|
||||
|
||||
|
||||
let aggregation = [];
|
||||
|
||||
let test = false;
|
||||
|
||||
if (test) {
|
||||
aggregation = [...aggregation, ...passo4];
|
||||
} else {
|
||||
// aggregation = [...aggregation, ...passo1];
|
||||
aggregation = [...aggregation, ...passo2];
|
||||
aggregation = [...aggregation, ...passo2b];
|
||||
aggregation = [...aggregation, ...passo3];
|
||||
}
|
||||
|
||||
db.movements.aggregate(aggregation);
|
||||
Reference in New Issue
Block a user