Home:ALL Converter>Retrieve Array Of Documents in MongoDB

Retrieve Array Of Documents in MongoDB

Ask Time:2013-03-14T13:33:42         Author:user1198485

Json Formatter

I have a MongoDB Document like as follows

{
"_id":1,
"name":"XYZ"

ExamScores:[
{ExamName:"Maths", UnitTest:1, Score:100},
{ExamName:"Maths", UnitTest:2, Score:80},
{ExamName:"Science", UnitTest:1, Score:90}
]
}

I Need to retrieve this document so that it has to show only Maths Array. Like as follows

{
    "_id":1,
    "name":"XYZ"

    ExamScores:[
    {ExamName:"Maths", UnitTest:1, Score:100},
    {ExamName:"Maths", UnitTest:2, Score:80},        
    ]
    }

How Can I Do That ?

Author:user1198485,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/15401928/retrieve-array-of-documents-in-mongodb
yy