Translate EXISTS-over-UNNEST subquery to $elemMatch

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Query
    • None
    • 5
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Support the HQL EXISTS subquery pattern that filters on elements of an embedded array, translating it to MongoDB's $elemMatch operator.

      Example HQL:

      SELECT c FROM Cart c
      WHERE EXISTS (SELECT 1 FROM LATERAL UNNEST(c.lineItems) li WHERE li.sku = 'WIDGET-1' AND li.qty > 2)
      

      Expected MQL:

      { "$match": { "lineItems": { "$elemMatch": { "sku": "WIDGET-1", "qty": { "$gt": 2 } } } } }
      

      This shape preserves parent cardinality — one result row per matching Cart regardless of how many lineItems match — and maps naturally to $elemMatch without requiring $unwind.

            Assignee:
            Jeffrey Yemin
            Reporter:
            Nathan Xu (Inactive)
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: