I've defined some simple cursor as find() on some collection.
cursor = db.students.find()
Student has following schema:
"_id" : 19,
"name" : "Gisela Levin",
"scores" : [
{
"type" : "exam",
"score" : 44.51211101958831
},
{
"type" : "quiz",
"score" : 0.6578497966368002
},
{
"type" : "homework",
"score" : 93.36341655949683
},
{
"type" : "homework",
"score" : 49.43132782777443
}
]
I want to iterate cursor and print a document. I try like that:
cursor.forEach(function(o){print(o)})
It prints only this:
[object Object]
If I modify a loop to select some simple property it works:
cursor.forEach(function(o){print(o._id)})
Though if I change it to print scores it prints this:
[object Object],[object Object],[object Object],[object Object]
Is there any function to print a json document in mongodb shell?