nuova veste grafica: myskills, mygoods, mybachecas, myhosps,

- cambiato id (da numero a stringa)
This commit is contained in:
Surya Paolo
2023-04-07 02:45:21 +02:00
parent 8a77dabc22
commit 94ef2c4c85
15 changed files with 1582 additions and 972 deletions

View File

@@ -10,91 +10,343 @@ let aggregation = [
{
$match: {
idapp: "13",
},
},
{
$sort: {
date_updated: -1,
},
},
{
$addFields: {
myId1: {
$toObjectId: "$userId",
},
},
},
{
$lookup: {
from: "users",
localField: "myId1",
foreignField: "_id",
as: "user",
},
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
$arrayElemAt: [
"$user",
0,
],
},
"$$ROOT",
],
},
},
},
{
$project: {
recGood: 1,
sectorGood: 1,
idSectorGood: 1,
idGood: 1,
mygood: 1,
idStatusSkill: 1,
idContribType: 1,
"profile.username_telegram": 1,
"profile.favorite": 1,
"profile.bookmark": 1,
idCity: 1,
pub_to_share: 1,
numLevel: 1,
adType: 1,
photos: 1,
note: 1,
website: 1,
descr: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1,
lasttimeonline: 1,
comune: 1,
mycities: 1,
"profile.img": 1,
"profile.mygroups": 1,
"profile.qualifica": 1,
"profile.resid_province": 1,
reported: 1,
date_report: 1,
username_who_report: 1,
},
},
{
$lookup: {
from: "goods",
localField: "idGood",
foreignField: "_id",
as: "recGood",
},
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
$arrayElemAt: [
"$recGood",
0,
],
},
"$$ROOT",
],
},
},
},
{
$project: {
recGood: 1,
sectorGood: 1,
idSectorGood: 1,
idGood: 1,
mygood: 1,
idStatusSkill: 1,
idContribType: 1,
"profile.username_telegram": 1,
"profile.favorite": 1,
"profile.bookmark": 1,
idCity: 1,
pub_to_share: 1,
numLevel: 1,
adType: 1,
photos: 1,
note: 1,
website: 1,
descr: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1,
lasttimeonline: 1,
comune: 1,
mycities: 1,
"profile.img": 1,
"profile.mygroups": 1,
"profile.qualifica": 1,
"profile.resid_province": 1,
reported: 1,
date_report: 1,
username_who_report: 1,
},
},
{
$lookup: {
from: "sectorgoods",
localField: "idSectorGood",
foreignField: "_id",
as: "sectorGood",
},
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
$arrayElemAt: [
"$sectorGood",
0,
],
},
"$$ROOT",
],
},
},
},
{
$project: {
recGood: 1,
sectorGood: 1,
idSectorGood: 1,
idGood: 1,
mygood: 1,
idStatusSkill: 1,
idContribType: 1,
"profile.username_telegram": 1,
"profile.favorite": 1,
"profile.bookmark": 1,
idCity: 1,
pub_to_share: 1,
numLevel: 1,
adType: 1,
photos: 1,
note: 1,
website: 1,
descr: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1,
lasttimeonline: 1,
comune: 1,
mycities: 1,
"profile.img": 1,
"profile.mygroups": 1,
"profile.qualifica": 1,
"profile.resid_province": 1,
reported: 1,
date_report: 1,
username_who_report: 1,
},
},
{
$lookup: {
from: "cities",
localField: "idCity",
foreignField: "_id",
as: "mycities",
},
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
$arrayElemAt: [
"$mycities",
0,
],
},
"$$ROOT",
],
},
},
},
{
$project: {
recGood: 1,
sectorGood: 1,
idSectorGood: 1,
idGood: 1,
mygood: 1,
idStatusSkill: 1,
idContribType: 1,
"profile.username_telegram": 1,
"profile.favorite": 1,
"profile.bookmark": 1,
idCity: 1,
pub_to_share: 1,
numLevel: 1,
adType: 1,
photos: 1,
note: 1,
website: 1,
descr: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1,
lasttimeonline: 1,
comune: 1,
mycities: 1,
"profile.img": 1,
"profile.mygroups": 1,
"profile.qualifica": 1,
"profile.resid_province": 1,
reported: 1,
date_report: 1,
username_who_report: 1,
},
},
{
$match: {
$or: [
{
deleted: {
$exists: false,
},
$and: [
{
"profile.mygroups": {
$elemMatch: {
groupname: {
$in: [
"000017",
"risoprova",
"VillaggiamoItalia",
"Terraw",
"RisoBenevento",
"111",
"gruppodefaultriso",
"pontiUmani",
],
},
},
},
},
{
pub_to_share: 1,
},
],
},
{
deleted: {
$exists: true,
$eq: false,
},
$or: [
{
pub_to_share: {
$exists: false,
},
},
{
pub_to_share: {
$exists: true,
$eq: 0,
},
},
],
},
],
},
},
{
$match: {
$and: [
{
"mycities.reg": "EMR",
},
],
},
},
{
$group: {
_id: "$aportador_solidario",
_id: null,
count: {
$sum: 1,
},
},
},
{
$match: { "count": { $gte: 2 } }
},
{
$sort: {
count: -1,
},
},
{
$lookup: {
from: "users",
let: {
username: "$_id",
idapp: "13",
},
pipeline: [
{
$match: {
$expr: {
$and: [
{
$eq: [
"$$username",
"$username",
],
},
{
$eq: [
"$$idapp",
"$idapp",
],
},
],
},
},
},
],
as: "user",
},
},
{ $unwind: "$user" },
{
$replaceRoot: {
newRoot: {
$mergeObjects: [ "$user", "$$ROOT" ],
results: {
$push: "$$ROOT",
},
},
},
{
$project: {
_id: 0,
count: 1,
aportador_solidario: 1,
username: 1,
name: 1,
surname: 1,
lasttimeonline: 1,
idapp: 1,
"profile.img": 1,
rows: {
$slice: [
"$results",
0,
10,
],
},
},
},
];
db.users.aggregate(aggregation);
db.myskills.aggregate(aggregation);

431
mongodb/Favorite.mongodb Normal file
View File

@@ -0,0 +1,431 @@
use('test_FreePlanet');
let aggregation = [
{
$match: {
idapp: "13",
},
},
{
$sort: {
date_updated: -1,
},
},
{
$lookup: {
from: "users",
let: {
tab: 1,
id: "$_id",
},
pipeline: [
{
$unwind: "$profile.favorite",
},
{
$match: {
$expr: {
$and: [
{
$eq: [
"$profile.favorite.id",
"$$id",
],
},
{
$eq: [
"$profile.favorite.tab",
"$$tab",
],
},
{
$eq: [
"$idapp",
"13",
],
},
],
},
},
},
{ $project: { username: 1, _id: 0 } },
],
as: "myfav",
},
},
{
$lookup: {
from: "users",
let: {
tab: 1,
id: "$_id",
},
pipeline: [
{
$unwind: "$profile.bookmark",
},
{
$match: {
$expr: {
$and: [
{
$eq: [
"$profile.bookmark.id",
"$$id",
],
},
{
$eq: [
"$profile.bookmark.tab",
"$$tab",
],
},
],
},
},
},
],
as: "mybook",
},
},
{
$addFields: {
myId1: {
$toObjectId: "$userId",
},
},
},
{
$lookup: {
from: "users",
localField: "myId1",
foreignField: "_id",
as: "user",
},
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
$arrayElemAt: [
"$user",
0,
],
},
"$$ROOT",
],
},
},
},
{
$project: {
recSkill: 1,
sector: 1,
idSector: 1,
idSkill: 1,
myskill: 1,
idStatusSkill: 1,
idContribType: 1,
"profile.username_telegram": 1,
"profile.favorite": 1,
"profile.bookmark": 1,
idCity: 1,
pub_to_share: 1,
numLevel: 1,
adType: 1,
photos: 1,
note: 1,
website: 1,
descr: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1,
lasttimeonline: 1,
comune: 1,
mycities: 1,
"profile.img": 1,
"profile.mygroups": 1,
"profile.qualifica": 1,
"profile.resid_province": 1,
reported: 1,
date_report: 1,
username_who_report: 1,
myfav: 1,
mybook: 1,
},
},
{
$lookup: {
from: "skills",
localField: "idSkill",
foreignField: "_id",
as: "recSkill",
},
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
$arrayElemAt: [
"$recSkill",
0,
],
},
"$$ROOT",
],
},
},
},
{
$project: {
recSkill: 1,
sector: 1,
idSector: 1,
idSkill: 1,
myskill: 1,
idStatusSkill: 1,
idContribType: 1,
"profile.username_telegram": 1,
"profile.favorite": 1,
"profile.bookmark": 1,
idCity: 1,
pub_to_share: 1,
numLevel: 1,
adType: 1,
photos: 1,
note: 1,
website: 1,
descr: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1,
lasttimeonline: 1,
comune: 1,
mycities: 1,
"profile.img": 1,
"profile.mygroups": 1,
"profile.qualifica": 1,
"profile.resid_province": 1,
reported: 1,
date_report: 1,
username_who_report: 1,
myfav: 1,
mybook: 1,
},
},
{
$lookup: {
from: "sectors",
localField: "idSector",
foreignField: "_id",
as: "sector",
},
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
$arrayElemAt: [
"$sector",
0,
],
},
"$$ROOT",
],
},
},
},
{
$project: {
recSkill: 1,
sector: 1,
idSector: 1,
idSkill: 1,
myskill: 1,
idStatusSkill: 1,
idContribType: 1,
"profile.username_telegram": 1,
"profile.favorite": 1,
"profile.bookmark": 1,
idCity: 1,
pub_to_share: 1,
numLevel: 1,
adType: 1,
photos: 1,
note: 1,
website: 1,
descr: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1,
lasttimeonline: 1,
comune: 1,
mycities: 1,
"profile.img": 1,
"profile.mygroups": 1,
"profile.qualifica": 1,
"profile.resid_province": 1,
reported: 1,
date_report: 1,
username_who_report: 1,
myfav: 1,
mybook: 1,
},
},
{
$lookup: {
from: "cities",
localField: "idCity",
foreignField: "_id",
as: "mycities",
},
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
$arrayElemAt: [
"$mycities",
0,
],
},
"$$ROOT",
],
},
},
},
{
$project: {
recSkill: 1,
sector: 1,
idSector: 1,
idSkill: 1,
myskill: 1,
idStatusSkill: 1,
idContribType: 1,
"profile.username_telegram": 1,
"profile.favorite": 1,
"profile.bookmark": 1,
idCity: 1,
pub_to_share: 1,
numLevel: 1,
adType: 1,
photos: 1,
note: 1,
website: 1,
descr: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1,
lasttimeonline: 1,
comune: 1,
mycities: 1,
"profile.img": 1,
"profile.mygroups": 1,
"profile.qualifica": 1,
"profile.resid_province": 1,
reported: 1,
date_report: 1,
username_who_report: 1,
myfav: 1,
mybook: 1,
},
},
{
$match: {
$or: [
{
$and: [
{
"profile.mygroups": {
$elemMatch: {
groupname: {
$in: [
"000017",
"risoprova",
"VillaggiamoItalia",
"Terraw",
"RisoBenevento",
"111",
"gruppodefaultriso",
"pontiUmani",
],
},
},
},
},
{
pub_to_share: 1,
},
],
},
{
$or: [
{
pub_to_share: {
$exists: false,
},
},
{
pub_to_share: {
$exists: true,
$eq: 0,
},
},
],
},
],
},
},
{
$match: {
$and: [
{
"mycities.reg": "EMR",
},
],
},
},
{
$group: {
_id: null,
count: {
$sum: 1,
},
results: {
$push: "$$ROOT",
},
},
},
{
$project: {
count: 1,
rows: {
$slice: [
"$results",
0,
10,
],
},
},
},
];
db.myskills.aggregate(aggregation);

352
mongodb/MySkills.mongodb Normal file
View File

@@ -0,0 +1,352 @@
// 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 aggregation = [
{
$match: {
idapp: "13",
},
},
{
$sort: {
date_updated: -1,
},
},
{
$addFields: {
myId1: {
$toObjectId: "$userId",
},
},
},
{
$lookup: {
from: "users",
localField: "myId1",
foreignField: "_id",
as: "user",
},
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
$arrayElemAt: [
"$user",
0,
],
},
"$$ROOT",
],
},
},
},
{
$project: {
recGood: 1,
sectorGood: 1,
idSectorGood: 1,
idGood: 1,
mygood: 1,
idStatusSkill: 1,
idContribType: 1,
"profile.username_telegram": 1,
"profile.favorite": 1,
"profile.bookmark": 1,
idCity: 1,
pub_to_share: 1,
numLevel: 1,
adType: 1,
photos: 1,
note: 1,
website: 1,
descr: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1,
lasttimeonline: 1,
comune: 1,
mycities: 1,
"profile.img": 1,
"profile.mygroups": 1,
"profile.qualifica": 1,
"profile.resid_province": 1,
reported: 1,
date_report: 1,
username_who_report: 1,
},
},
{
$lookup: {
from: "goods",
localField: "idGood",
foreignField: "_id",
as: "recGood",
},
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
$arrayElemAt: [
"$recGood",
0,
],
},
"$$ROOT",
],
},
},
},
{
$project: {
recGood: 1,
sectorGood: 1,
idSectorGood: 1,
idGood: 1,
mygood: 1,
idStatusSkill: 1,
idContribType: 1,
"profile.username_telegram": 1,
"profile.favorite": 1,
"profile.bookmark": 1,
idCity: 1,
pub_to_share: 1,
numLevel: 1,
adType: 1,
photos: 1,
note: 1,
website: 1,
descr: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1,
lasttimeonline: 1,
comune: 1,
mycities: 1,
"profile.img": 1,
"profile.mygroups": 1,
"profile.qualifica": 1,
"profile.resid_province": 1,
reported: 1,
date_report: 1,
username_who_report: 1,
},
},
{
$lookup: {
from: "sectorgoods",
localField: "idSectorGood",
foreignField: "_id",
as: "sectorGood",
},
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
$arrayElemAt: [
"$sectorGood",
0,
],
},
"$$ROOT",
],
},
},
},
{
$project: {
recGood: 1,
sectorGood: 1,
idSectorGood: 1,
idGood: 1,
mygood: 1,
idStatusSkill: 1,
idContribType: 1,
"profile.username_telegram": 1,
"profile.favorite": 1,
"profile.bookmark": 1,
idCity: 1,
pub_to_share: 1,
numLevel: 1,
adType: 1,
photos: 1,
note: 1,
website: 1,
descr: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1,
lasttimeonline: 1,
comune: 1,
mycities: 1,
"profile.img": 1,
"profile.mygroups": 1,
"profile.qualifica": 1,
"profile.resid_province": 1,
reported: 1,
date_report: 1,
username_who_report: 1,
},
},
{
$lookup: {
from: "cities",
localField: "idCity",
foreignField: "_id",
as: "mycities",
},
},
{
$replaceRoot: {
newRoot: {
$mergeObjects: [
{
$arrayElemAt: [
"$mycities",
0,
],
},
"$$ROOT",
],
},
},
},
{
$project: {
recGood: 1,
sectorGood: 1,
idSectorGood: 1,
idGood: 1,
mygood: 1,
idStatusSkill: 1,
idContribType: 1,
"profile.username_telegram": 1,
"profile.favorite": 1,
"profile.bookmark": 1,
idCity: 1,
pub_to_share: 1,
numLevel: 1,
adType: 1,
photos: 1,
note: 1,
website: 1,
descr: 1,
date_created: 1,
date_updated: 1,
userId: 1,
username: 1,
name: 1,
surname: 1,
lasttimeonline: 1,
comune: 1,
mycities: 1,
"profile.img": 1,
"profile.mygroups": 1,
"profile.qualifica": 1,
"profile.resid_province": 1,
reported: 1,
date_report: 1,
username_who_report: 1,
},
},
{
$match: {
$or: [
{
$and: [
{
"profile.mygroups": {
$elemMatch: {
groupname: {
$in: [
"000017",
"risoprova",
"VillaggiamoItalia",
"Terraw",
"RisoBenevento",
"111",
"gruppodefaultriso",
"pontiUmani",
],
},
},
},
},
{
pub_to_share: 1,
},
],
},
{
$or: [
{
pub_to_share: {
$exists: false,
},
},
{
pub_to_share: {
$exists: true,
$eq: 0,
},
},
],
},
],
},
},
{
$match: {
$and: [
{
"mycities.reg": "EMR",
},
],
},
},
{
$group: {
_id: null,
count: {
$sum: 1,
},
results: {
$push: "$$ROOT",
},
},
},
{
$project: {
count: 1,
rows: {
$slice: [
"$results",
0,
10,
],
},
},
},
];
db.myskills.aggregate(aggregation);

View File

@@ -278,3 +278,11 @@ if (test) {
// 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);
db.getCollection('myskills').deleteMany({ '_id': { $lte: 10000 }})
db.getCollection('mygoods').deleteMany({ '_id': { $lte: 10000 }})
db.getCollection('mybachecas').deleteMany({ '_id': { $lte: 10000 }})
db.getCollection('myhosps').deleteMany({ '_id': { $lte: 10000 }})
db.getCollection('mygroups').deleteMany({ '_id': { $lte: 10000 }})