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

New Agg Metadata Source to Generate A Single Empty Document

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 4.0.0
    • Component/s: Querying
    • None
    • Query Execution

      There are quite a few situations in which {$limit: 0} would be useful, for instance, currently in the BI-Connector we use $collStats to inject a single document when we need to pushdown a subquery that needs exactly one projected result out.

      However, $collStats has some issues, and we think $facet might be a better choice. But in this case we would prefer {$limit: 0} to {$limit: 1}, since we literally don't care about the result, so for example:

      select a from foo inner join (select "hello")
      

      We would like to push down the subquery select "hello" as:

      {$facet: {out: [{$limit: 0}]}}
      {$project: {'hello': 'hello', '_id': 0}}
      

      At some future point this could even be a optimized to not look at any documents (currently on a collection of 100K docs, {$limit: 1} will look at 853 of them in a $facet on server 4.0), but for now, simply changing the error condition to be negative from non-positive would be an improvement.

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            patrick.meredith@mongodb.com Patrick Meredith
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: