如何在mongoDB中对集合记录中的数组进行排序
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
}
]}我正在尝试这个咒语....
doc = db.students.find() for (_id,score) in doc.scores: print _id,score
但它不起作用。
郎朗坤
温温酱
长风秋雁
噜噜哒
随时随地看视频慕课网APP
相关分类