MongoDB 菜鸟在这里...
好的,我有一组学生,每个学生都有一个类似于以下的记录......我想按降序对“类型”:“家庭作业”分数进行排序。
这个咒语在 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
但它不起作用。