[SERVER-80458] $count aggregation stage does return nothing when count is zero Created: 28/Aug/23  Updated: 15/Sep/23

Status: Backlog
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 6.0.9
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Daniel Müller Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-54958 Empty result when counting from empty... Backlog
Assigned Teams:
Query Optimization
Operating System: ALL
Steps To Reproduce:

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 }

Participants:

 Description   

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/


Generated at Thu Feb 08 06:43:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.