KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a collection of students, each with a record that looks like the following and I want to sort the scores array in descending order of score . what does that incantation look like on the 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 } ] } I'm trying this incantation.... doc = db.students.find() for (_id,score) in doc.scores: print _id,score but it's not working.
Tags (comma-separated)
Save Edits
Cancel