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" },
}
}
])