This is probably a noobish question, however I have spent quite some time on it now.
So this is my structure, highly minimized:
{
name : 'Some dude',
deck : [{
name : 'Awesome card',
value : 30
},
{
name : 'another awesome card',
value: 50
}]
}
I want to select from all cards in the deck, where name == ‘Awesome card’, returning this
{
name : 'Some dude',
deck : [{
name : 'Awesome card',
value : 30
}]
}
been trying loads of commands like
db.heroes.find({name : “Some dude”}, {‘deck’ : 1, ‘deck.name’ : ‘Awesome card})
How should I query this?
You can use the
$position operator which identifies the index of the matcheddeckarray element in your field selection: