- Le immagini uploadate non vengono visualizzate subito... cache... aggiungere la versione dell'immagine: vers_img
- Aggiunto il Server TESTRISO e TEST_PCB.
This commit is contained in:
@@ -5487,6 +5487,38 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
async listCollectionsBySize() {
|
||||
let output = ""; // Variabile per memorizzare l'output
|
||||
|
||||
try {
|
||||
const conn = mongoose.connection;
|
||||
|
||||
// Ottieni le collezioni e calcola la dimensione
|
||||
const collections = await conn.db.listCollections().toArray();
|
||||
|
||||
// Calcola la dimensione per ciascuna collezione
|
||||
const collectionSizes = await Promise.all(collections.map(async (collection) => {
|
||||
const stats = await conn.db.collection(collection.name).stats();
|
||||
return { name: collection.name, size: stats.size };
|
||||
}));
|
||||
|
||||
// Ordina le collezioni per dimensione
|
||||
collectionSizes.sort((a, b) => b.size - a.size); // Ordine decrescente
|
||||
|
||||
output += "Collezioni ordinate per dimensione:\n"; // Inizio dell'output
|
||||
collectionSizes.forEach(collection => {
|
||||
const sizeInMB = (collection.size / (1024 * 1024)).toFixed(2); // Converti in MB
|
||||
output += `Collezione: ${collection.name}, Dimensione: ${sizeInMB} MB\n`; // Aggiungi all'output
|
||||
});
|
||||
|
||||
return output; // Restituisci l'output alla fine
|
||||
} catch (error) {
|
||||
console.error("Errore:", error);
|
||||
return `Errore: ${error.message}`; // Restituisci l'errore come stringa
|
||||
}
|
||||
},
|
||||
|
||||
ImageDownloader,
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user