Files
Deep-Package-Inspection/test_countries2.js
T

21 lines
905 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();
const data = raw.filter(r => r.country_code && r.country_code !== 'Unknown' && r.country_code.length === 2);
const dataWithBW = data.filter(r => r.download > 0 || r.upload > 0);
console.log('Total valid countries:', data.length);
console.log('Countries with > 0 bandwidth:', dataWithBW.length);
mongoose.disconnect();
});