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

XMLWordPrintableJSON

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

      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
              Reporter:
              David Storch
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: