mongoose的多表聚合查询问题
var StudentSchema = new mongoose.Schema({ sno: String, sname: String, class: { type: mongoose.Schema.Types.ObjectId, ref: ‘Class’ } });
var ClassSchema = new mongoose.Schema({ cno: Number, cname: String });
目的: 查询班级信息, 并统计班级人数.
标准SQL select cno,cname,count(class) from class,student where student.class=class._id group by cno,cname;
问题: 各位大神帮忙用mongoose怎么实现如上的聚合查询呢 ?