fix: ordinamento membri (namecomplete (concat: name, surname, username)

This commit is contained in:
Surya Paolo
2023-04-12 15:37:54 +02:00
parent 5bb6611384
commit f13786fca1
10 changed files with 500 additions and 86 deletions

203
mongodb/Members.mongodb Normal file
View File

@@ -0,0 +1,203 @@
use('test_FreePlanet');
let aggregation = [
{
$match: {
idapp: "13",
"profile.mycircuits": {
$elemMatch: {
circuitname: {
$eq: "Circuito RIS Bologna",
},
},
},
},
},
{
$lookup: {
from: "circuits",
as: "circuit",
let: {
circuitname: "Circuito RIS Bologna",
idapp: "$idapp",
},
pipeline: [
{
$match: {
$expr: {
$and: [
{
$eq: [
"$name",
"$$circuitname",
],
},
{
$eq: [
"$idapp",
"$$idapp",
],
},
],
},
},
},
],
},
},
{
$unwind: "$circuit",
},
{
$project: {
username: 1,
name: 1,
surname: 1,
date_reg: 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",
},
{
$match: {
idapp: "13",
},
},
{
$addFields: {
myId1: {
$toObjectId: "$userId",
},
namecomplete: {
$concat: [
{
$toLower: "$name",
},
{
$toLower: "$surname",
},
{ $toLower: "$username" },
],
},
},
},
{
$lookup: {
from: "users",
localField: "myId1",
foreignField: "_id",
as: "user",
},
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
$arrayElemAt: [
"$user",
0,
],
},
"$$ROOT",
],
},
},
},
{
$project: {
username: 1,
name: 1,
surname: 1,
"profile.img": 1,
"profile.mycircuits": 1,
"profile.qualifica": 1,
"profile.resid_province": 1,
"account._id": 1,
"account.saldo": 1,
"account.fidoConcesso": 1,
"account.qta_maxConcessa": 1,
"account.totTransato": 1,
reported: 1,
date_report: 1,
username_who_report: 1,
namecomplete: 1,
date_reg: 1,
},
},
{
$sort: {
date_reg: 1,
},
},
{
$group: {
_id: null,
count: {
$sum: 1,
},
results: {
$push: "$$ROOT",
},
},
},
{
$project: {
count: 1,
rows: {
$slice: [
"$results",
1,
15,
],
},
},
},
];
db.users.aggregate(aggregation);

View File

@@ -0,0 +1,23 @@
use('test_FreePlanet');
let aggregation = [
{
$match: {
idapp: "13",
"profile.favorite": {
$elemMatch:
{ id: '10256', tab: 4 }
}
},
},
{
$group:
{
_id: null,
count: { $sum: 1 },
}
},
{ $project: { _id: 0 } }
];
db.users.aggregate(aggregation);