Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-10401

Docs for SERVER-29620: Add shorthand syntax for retrieving the record count for a collection using the $collStats agg stage

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.5.9
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Documentation Request Summary:

      This commit adds a new option to the $collStats aggregation stage, allowing the user to get a 'fast count' for the number of records in the given collection. The count value must be an Object.

      A more detailed description is located in the design document:
      https://docs.google.com/document/d/1kHIQLLZv7ZMlW9aktZ6CIQdC1L8j3_PJxBdUx_q3FcQ/edit#heading=h.wybafdaad3h

      Engineering Ticket 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.

            Assignee:
            jonathan.destefano@mongodb.com Jonathan DeStefano
            Reporter:
            emily.hall Emily Hall
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              6 years, 29 weeks, 6 days ago