Provide aggregation stage to abort pipeline halfway through

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Duplicate
    • Priority: Minor - P4
    • None
    • Affects Version/s: 4.4.6
    • Component/s: None
    • None
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      We have some slow large aggregation pipelines where a $limit at the end is not sufficient to prevent slow queries, and where a $limit early in the pipeline would give incorrect results.

      Hence we want to have a way to limit early but abort the query instantly if this limit is hit:

      For example:

       

      aggregate([
         { $match: {....}},
         { $imaginaryNewAbortOnCondition: { 
              count: {$gt: 100}, 
              message: "Too many rockets found, please limit the search range"
           }
         },
         { $lookupUnwindOrOtherExpensiveAggregations: {...}},
         { $limit: 100 }
      ])
      

      I think limit is our main use case but one could also imagine other uses where a more dynamic condition is useful.

       

            Assignee:
            Edwin Zhou
            Reporter:
            Erikvc Erik
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: