The data model is something like this:
"_id":...
"special_offers": [ 0 => Object, 1 => Object, ...]
I just need to get 0 => Object
, I mean, the first item of the special_offers
array.
Here is what I’ve tried:
But as you can see, all items of the array are visible in the result. Any idea how can I get that?
2
Answers
From https://www.mongodb.com/docs/manual/tutorial/project-fields-from-query-results/#project-specific-array-elements-in-the-returned-array:
If you know the
_id
value of the first element then you can do:Or if you only know the
_id
of the parent document then you can do: