【发布时间】:2012-11-07 03:26:05
【问题描述】:
我有一组学生,每个学生的记录如下所示,我想按score 的降序对scores 数组进行排序。
这个咒语在 mongo shell 上是什么样子的?
> db.students.find({'_id': 1}).pretty()
{
"_id" : 1,
"name" : "Aurelia Menendez",
"scores" : [
{
"type" : "exam",
"score" : 60.06045071030959
},
{
"type" : "quiz",
"score" : 52.79790691903873
},
{
"type" : "homework",
"score" : 71.76133439165544
},
{
"type" : "homework",
"score" : 34.85718117893772
}
]
}
我正在尝试这个咒语......
doc = db.students.find()
for (_id,score) in doc.scores:
print _id,score
但它不起作用。
【问题讨论】:
标签: javascript arrays mongodb sorting