I have the following model in mongodb:
{
sport: 'Football',
site: 'Bet365',
data: [
{
_id: '1',
rating: 98.12,
bets: [
{
exchange: 'Smarkets',
odds1: 3.2,
odds2: 3.3
},
{
exchange: 'Matchbook',
odds1: 1.5,
odds2: 1.52
},
{
exchange: 'Betfair',
odds1: 2.0,
odds2: 2.1
},
]
},
{
_id: '2',
rating: 99.50,
bets: [
{
exchange: 'Smarkets',
odds1: 2.1,
odds2: 2.12
},
{
exchange: 'Smarkets',
odds1: 1.4,
odds2: 1.4
},
{
exchange: 'Smarkets',
odds1: 2.0,
odds2: 2.05
},
]
},
]
}
Is there a query I can make to this to only get the embedded objects in the data array if every exchange in the bets array matches the one we're using as a filter.
For example, I want something like the query below, but I only want it to return the object with '_id' = '2' as that is the only object where every exchange is 'Smarkets'.
db.find('data.bets.exchange': 'Smarkets')
// how do I change this to only get the object with _id '2'?