我有一组学生,每个学生都有一个如下所示的记录,我想scores
按score
.
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
但它不起作用。