If this is my data:
{
owner: 'John',
pets:[
{
name: 'Oscar',
age: 7,
type: 'dog'
},{
name: 'Oscar II',
age: 3,
type: 'dog'
}
]
},{
owner: 'Sally',
pets:[
{
name: 'Spot',
age: 7,
type: 'cat'
},{
name: 'Mister Dog',
age: 3,
type: 'dog'
}
]
}
How can I build a query to get every owner that has a dog that is 7.
I tried:
Owners.findOne({
'pets.age': 7,
'pets.type': 'dog'
});
But this returns every owner who has a pet with an age of 7 OR with a type of dog. In the case of the data above it return both Sally & John. How can I just get John?