MongoDB noob在这里......
好的,我有一个学生集合,每个都有一个如下所示的记录....我想按照降序排序'类型':'家庭作业'分数.
那个咒语在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
}
]
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试这个咒语....
doc = db.students.find()
for (_id,score) in doc.scores:
print _id,score
Run Code Online (Sandbox Code Playgroud)
但它不起作用.