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

$count aggregation stage does return nothing when count is zero

    • Query Optimization
    • ALL
    • Hide

      1: Create a new empty collection

      2: Run the sample aggregation

      [ {  $count: "total" }, ]

      3: Notice that it does not return anything. Expected result:

      { "total": 0 }

      4: Add an object to the collection

      5: Run the aggregation again

      6: Returns an expected result of:

      "total": 1 }
      Show
      1: Create a new empty collection 2: Run the sample aggregation [ { $count: "total" }, ] 3: Notice that it does not return anything. Expected result: { "total" : 0 } 4: Add an object to the collection 5: Run the aggregation again 6: Returns an expected result of: {  "total" : 1 }

      I was using the aggregation stage $count and noticed that if the input dataset was empty that $count does not return anything.

      I was expecting it to return 0.

      There is nothing specified in the docs to expect this behaviour.
      https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            daniel.mueller@surnet.ch Daniel Müller
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: