I have this mlab document:
{
"_id": {
"$oid": "572b2cdfc80eb653c302f5e9"
},
"year": 2014,
"students": [
{
"id": 5,
"firstName": "Joe",
"lastName": "know",
"GPA": 67
},
{
"id": 3,
"firstName": "Peter",
"lastName": "Jones",
"GPA": 77
},
{
"id": 6,
"firstName": "Yossi",
"lastName": "Haim",
"GPA": 68
},
{
"id": 13,
"firstName": "Chen",
"lastName": "Si",
"GPA": 92
}
]
}
Which i get with: (year is also a parameter)
gradeM= mongoose.model('Grade',grade);
gradeM.find({'year':year},'-_id').exec(function (err, data) {
if (err) console.log("err: " + err);
console.log(JSON.stringify(data));
});
As much as getting data from the collection i'm doing well but i wish to exclude from returned document all students array records in which GPA<90. Tried some different aggregate ans match functions but i can't seem to get the syntax correct.
End result should look like:
{
"year": 2014,
"students": [
{
"id": 13,
"firstName": "Chen",
"lastName": "Si",
"GPA": 92
}
]
}
I can always loop the document using JS but i'm looking for a way to get the ready result right away.
Thanks