Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-56832

Provide aggregation stage to abort pipeline halfway through

    • Type: Icon: Improvement Improvement
    • Resolution: Duplicate
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 4.4.6
    • Component/s: 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@mongodb.com Edwin Zhou
            Reporter:
            sflkjdsflksdmfslkdfj@mailinator.com Erikvc Erik
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: