Use array values as path to match documents

I had a play trying various things but the multi level proved to be tricky, where it could be n levels deep, using straight aggregation.
There was a similar question here:

That converts the document / element to an array and then searches. I guess you could set limits on lookups, i.e. that they need to be max 3 deep and then work out all possible options but that’s starting to sound 1) like a complete hack and 2) horrible slow.

I’d be interested to see if anyone else comes up with an approach within the aggregation framework without resorting to having the calling code do something.

My plan was to be an $unwind, then the dynamic matching, then $group back up to re-form the documents that satisfy the criteria.

John

1 Like