【发布时间】:2017-09-27 22:50:41
【问题描述】:
我在 mongo 中收集了数学、写作和阅读成绩优异的学生。我需要总结所有的数学、写作和阅读成绩。
例如,如果 3 名学生的数学各得 50,那么总和就是 150。
到目前为止我有:
db.student.aggregate([{$group:{"_id":null, total:{$sum:"$math score"}}}])
我在 Google 上花了大约一个小时试图弄清楚这一点。我使用 mongo 的经验为零,所以进展缓慢。
这是我的数据示例
{
"student_data":
[
{
"S-ID": 91371,
"gender": "male",
"race/ethnicity": "group B",
"parental level of education": "some college",
"lunch": "standard",
"test preparation course": "completed",
"math score": 44,
"reading score": 50,
"writing score": 48,
"Total Score": 142
},
【问题讨论】:
-
您能否提供一个示例数据库数据,以便我了解数据的存储方式
-
我添加了一些示例数据,我想我搞砸了,因为数据在数组中。
-
我已经添加了一个答案请检查它@hunter