Push complex conditions into $lookup joins

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: django
    • Python Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • 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:
            Unassigned
            Reporter:
            Emanuel Lupi
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: