Push complex conditions into $lookup joins

XMLWordPrintableJSON

    • 🔵 Done
    • Python Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Context

      Currently, simple conditions (simple lookups of one column=value)  are already pushed into $lookup, improving performance by filtering early. However, more complex conditions such as nested expressions, comparisons, or logical operators — are still applied after $lookup, which can be inefficient when working with large related datasets.
      MongoDB supports embedding these conditions directly into the $lookup pipeline using the let and pipeline options, allowing more selective joins.

      Definition of done

      • Extend $lookup handling to support complex conditions ($and, $or, $expr, etc.) within the inner pipeline.
      • Allow filter() conditions to be passed down into the inner $lookup stage when feasible.
      • Validate that variable scoping (let) and parameter substitution behave as expected.
      • Add tests for nested and mixed simple/complex condition cases.
      • Remove duplicate condition between outer and inner stages.

      Pitfalls

      • Complex expressions may require variable rewriting ($$ prefixes).

            Assignee:
            Emanuel Lupi
            Reporter:
            Emanuel Lupi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: