I have a document containing nested array data. I tried hopelessly to filter the data using $elemMatch
but I cannot figure out why it is not working.
{
'id' : 1,
'name' : 'test',
'modules' : [
{
name: 'foo',
mandatory: false,
group: [
{
name: g1
}]
},
{
name: 'bar',
mandatory: false,
group: [
{
name: g2
}]
}]
}
I tried using this query:
db.test.find(
{
modules: {
$elemMatch: {
name: "foo",
}
}
}
But it keeps returning all the modules. If I use mandatory: true
it returns nothing, which seems to indicates it works. Any idea what am I doing wrong? Thanks!