Tag: asynchronous javascript

Nodejs + Mongodb:聚合后查找数据

我是Nodejs和MongoDB的新手。 以下是我的数据集示例: { 'name': ABC, 'age':24, 'gender':male, … } 一般来说,我想要做的就是在使用它们来查找不同的数据集群之前对数据进行聚合。 具体来说,我想知道有多less人在不同的年龄段。 然后,find每个年龄段的人(文件)并存储它们。 这是我的代码: MongoClient.connect(url, function(err, db) { if(err) { console.log('Unable to connect to the mongoDB server. Error:', err); } else { db.collection('test').aggregate( [ { $group: { _id: "$age" , total: { $sum: 1 } } }, { $sort: { total: -1 } } ]).toArray(function(err, result) […]