0
我试图计算跨许多测试的测试结果的平均分数,但是文档在人物对象内嵌套了两个级别。下面MongoDB在嵌套集合中的平均值
我不能嵌套集合
{ "name" : "Person Name",
"tests" : [
{
"testID" : "01"
},
"scores" : {
"math" : 3.0,
"science" : 2.0
}
}
]
}
内获得平均是我的MongoDB的查询。
db.students.aggregate([
{
$project: {
mathAve: { $avg: "$math"},
scienceAve: { $avg: "$science" },
}
}
])