How to Dynamically Compare Fields Across Documents in an Aggregated Array in MongoDB

We cannot work with your sample documents as published.

Please read Formatting code and log snippets in posts and update accordingly.

But a better alternative is to create a

You would also need to provide a lot more details and examples of