I need to filter documents according to the value of the last element of a nested array using find
The reason I need it with find and not aggregation is the fact that the endpoint I’m sending the query to handle it is using only find. pretty weird but I gotta work with that at the moment.
I tried to use $arrayElemAt which is what I’ve found so far to handle it with find and I managed to get the first arrays value, but I can’t figure out how to select the ids array and to act according to innerName value.
If you are running 5.0 or more recent, you use $getField together with 2 calls to $arrayElemAt. Something along the following untested lines that results in an expression equals to the innerName of the last ids of the last matches: