19 lines
684 B
JavaScript
19 lines
684 B
JavaScript
const mongoose = require('mongoose');
|
|
mongoose.connect('mongodb://backone_inspect:backone_inspect@mongodb.prod.proit.id:27017/backone_inspect_0').then(async () => {
|
|
const db = mongoose.connection.db;
|
|
const raw = await db.collection('countrystats').aggregate([
|
|
{ $group: {
|
|
_id: '$country_name',
|
|
download: { $sum: '$download' },
|
|
upload: { $sum: '$upload' },
|
|
flow_count: { $sum: { $ifNull: ['$flows', 1] } },
|
|
country_code: { $first: '$country_name' }
|
|
}},
|
|
{ $sort: { download: -1 } },
|
|
{ $limit: 200 }
|
|
]).toArray();
|
|
console.log(raw.length, 'countries returned');
|
|
console.log(raw.slice(0, 10));
|
|
mongoose.disconnect();
|
|
});
|