使用mongoose 4.11.0进行组查询

我想用最后一个版本的mongoose做一个例子:

Patient.group({gender:true}) .then((result)=>{ console.log(result); }); 

病人是模型,你知道这是怎么回事?

你在找什么是mongoDB 聚合pipe道。 以下将根据性别对患者文件进行分组:

 Patient.aggregate( [ //{ // $match: {email: {$exists: true}} //you can also match some criteria //}, { $group: { _id: "$gender" } } ] ) .then((result) => { console.log(result); });