I have this documents:
//document 1
{
info : [
{
id : 100,
field : {
a : 1,
b : 2
}
},
{
id : 200,
field : {
a : 3,
b : 4
}
},
{
id : 300,
field : {
a : 5,
b : 6
}
}
]
},
//document 2
{
info : [
{
id : 400,
field : {
a : 7,
b : 8
}
},
{
id : 500,
field : {
a : 9,
b : 10
}
}
]
}
I need to find the id of the subdocument with the values field.a = 7 and field.b = 8 , that means the id value is 400.
What i have tried is $elemMatch but I can't get the result.
My attemps :
attemp 1:
db.mycollection.findOne({info : {$elemMatch : { 'field.$.a':7,'field.$.b':8 } } });
attemp 2:
db.mycollection.findOne({info:{$elemMatch:{$elemMatch:{'field.$.a':7,'field.$.b':8,}}}});
attemp 3:
db.mycollection.findOne({info:{$elemMatch:{$elemMatch:{'field.a.$':7,'field.b.$':8,}}}});
attemp 4:
db.mycollection.findOne({info:{$elemMatch:{'field.$.a':7,'field.$.b':8,}}});
db.mycollection.findOne({info : {$elemMatch : {field:{ 'a':7,'b':8 }} } });