【发布时间】:2018-05-22 09:14:26
【问题描述】:
我想知道我是否可以项目组中不存在的字段。 例如,我有以下集合,我想要所有学生中足球最高的学生的名字
{ "_id" : 1, "Snmae" : Alex, "score" : 97}
{ "_id" : 2, "Snmae" : Sara, "socre" : 97 }
{ "_id" : 3, "Snmae" : Sam, "socre" : 93 }
{ "_id" : 4, "Snmae" : Dan, "socre" : 77 }
db.stuudent.aggregate(
{$project:{_id:0,sname:1,score:1}},
{ $group : { _id : "", High_Score: { $max: "$score" }}}
);
愿望输出是
Sname:Alex,得分:97
Sname:Sara,得分:97
【问题讨论】:
标签: mongodb mongoose collections