Hello, im trying to query some nested documents at MongoDB. im using Mongoose.. my documents are like
[
{
"_id": "5a2ca2227c42ad67682731d4",
"description": "some descrition",
"photos": [
{
"_id": "5a2ca22b7c42ad67682731d5",
"approved": false,
"text":"good"
},
{
"_id": "5a2ca72b0a1aa173aaae07da",
"approved": true,
"text":"bad"
},
{
"_id": "5a2cabf85a41077a2f87d4e3",
"approved": false,
"text":"bad"
}
]
}
]
I Want to find only photos that have the value "good", at text attribute, here is my find code:
ObjectSchema.find({
'photos': {
$elemMatch : {
'text' : 'good'
}
}
},function(err,result){
console.log(result);
});
I Wanted only to return the objct with the element with value that match my query, but when one object of this list match, the whole list of photos come with the result, not only who match the text.. How can i query it, and bring only the element who match, in this case, only the element which have "good" in text..
im using nodejs + mongoose
Thank you!