I am trying to make a consultant on my MongoDB database:
What I want to do is to obtain some data that is integrated in a nested array and filter by one of this nested keys.
The document is the following:
[
{
"name": "PharmaMaria",
"country": "Spain",
"currency": "EUR",
"medicines": [
{
"name": "Medicine 1",
"type": "Suncream",
"price": 32,
},
{
"name": "Medicine 2",
"type": "Suncream",
"price": 5
},
{
"name": "Medicine 3",
"type": "Pills",
"price": 7
}
]
}
]
And I want to get something like this filtering by medicines.type
values = [
{
"name": "Medicine 1",
"price": 32
},
{
"name": "Medicine 2",
"price": 5
}
]
Here is the playground I created https://mongoplayground.net/p/_riatO8PKVp
Thanks!