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

Add shorthand syntax for retrieving the record count for a collection using the $collStats agg stage

    • Fully Compatible
    • Query 2017-06-19
    • 0

      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.

            Assignee:
            nicholas.zolnierz@mongodb.com Nicholas Zolnierz
            Reporter:
            david.storch@mongodb.com David Storch
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: