I have a nested document of following format:
{
_id: "1234567890",
course: {content: [{ id: 1,
children:[{
id: 1111
},
{
id: 2222
}
{
id: 3333
}]
},
{ id: 2,
children:[{
id: 4444
},
{
id: 5555
}
{
id: 6666
}]
}
]}
}
I'm trying to query the children based on id (course.content.children.id) using the following code from Node.js:
var query = {
'course.content.children.id': quizId,
};
var option = {
'course.content.children.$': 1,
};
db.getEntityWithOption(tablename,query,option,function(data,err){
res.send(data.course.content[0].children);
});
db.getEntityWithOption is wrapper method on top of db.find() method. when I call the method with quiz id 1, the above code return me the following complete array: `
{ id: 1,
children:[{
id: 1111
},
{
id: 2222
}
{
id: 3333
}]
}
But I need only the specific element of the array with id 1111 not the compete array. Can any life savior suggest me what I'm doing wrong here. TIA :)