0
对于下面的文档:聚合函数在MongoDB中,Parse.com
{
profile: String
[{
year: Integer,
quarter: Integer,
rate: Integer
}]
}
如何获得每季度排行榜?:
2014 1 3.5
2014 2 4.0
...
对于下面的文档:聚合函数在MongoDB中,Parse.com
{
profile: String
[{
year: Integer,
quarter: Integer,
rate: Integer
}]
}
如何获得每季度排行榜?:
2014 1 3.5
2014 2 4.0
...
假设您的个人资料作为数组的平均值。
db.collection.aggregate([
{"$unwind" : "$profile"},
{"$group": { "_id" : { "year": "$profile.year", "quarter": "$profile.quarter"}, average: { $avg: "$profile.rate" }}}
])
更多信息:
http://docs.mongodb.org/manual/reference/operator/aggregation/group/
http://docs.mongodb.org/manual/reference/operator/aggregation/unwind/