[SERVER-29620] Add shorthand syntax for retrieving the record count for a collection using the $collStats agg stage Created: 14/Jun/17  Updated: 30/Oct/23  Resolved: 16/Jun/17

Status: Closed
Project: Core Server
Component/s: Aggregation Framework, Querying
Affects Version/s: None
Fix Version/s: 3.5.9

Type: Improvement Priority: Major - P3
Reporter: David Storch Assignee: Nicholas Zolnierz
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Documented
is documented by DOCS-10401 Docs for SERVER-29620: Add shorthand ... Closed
Related
related to SERVER-22743 Provide fast (estimated) count command Closed
Backwards Compatibility: Fully Compatible
Sprint: Query 2017-06-19
Participants:
Linked BF Score: 0

 Description   

The number of documents in a collection can already be retrieved using $collStats in O(1) time—that is, without executing a query to count the total number of documents. However, we would like to provide syntactic sugar in order to make this easy. Specifically, we will add a count option to $collStats:

> db.myColl.aggregate([{$collStats: {count: {}}}]);
{
ns: "test.myColl",
localTime: ISODate("2017-06-02T15:48:46.510Z"),
count: 11
}

This aggregation will return a single document with the ns and localTime fields, just like other $collStats pipelines. The count will be reported in a new field called count.



 Comments   
Comment by Githook User [ 16/Jun/17 ]

Author:

{u'username': u'nzolnierzmdb', u'name': u'Nick Zolnierz', u'email': u'nicholas.zolnierz@mongodb.com'}

Message: SERVER-29620 Add shorthand syntax for retrieving the record count for a collection using the agg stage
Branch: master
https://github.com/mongodb/mongo/commit/8ec35cb932d07eb034beee2b1938800675fb3c0c

Comment by Githook User [ 15/Jun/17 ]

Author:

{u'username': u'jseyster', u'name': u'Justin Seyster', u'email': u'justin.seyster@mongodb.com'}

Message: Revert "SERVER-29620 Add shorthand syntax for retrieving the record count for a collection using the agg stage"

This reverts commit 1efbf03521e9c6d85df33ab6786f6c121d8b56c2.
Branch: master
https://github.com/mongodb/mongo/commit/2ac7dedaac717c125f25d797badccd644dc1db00

Comment by Kyle Suarez [ 15/Jun/17 ]

Marking Drivers Changes as "Maybe", as it's possible in the future that drivers may want to expose fast count to the users in this manner.

Comment by Githook User [ 15/Jun/17 ]

Author:

{u'username': u'nzolnierzmdb', u'name': u'Nick Zolnierz', u'email': u'nicholas.zolnierz@mongodb.com'}

Message: SERVER-29620 Add shorthand syntax for retrieving the record count for a collection using the agg stage
Branch: master
https://github.com/mongodb/mongo/commit/1efbf03521e9c6d85df33ab6786f6c121d8b56c2

Generated at Thu Feb 08 04:21:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.