Skip to content

DOCS-8914: Add $collStats aggregation operator #2750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions source/includes/ref-toc-aggregation-pipeline-operator.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
name: :pipeline:`$collStats`
file: /reference/operator/aggregation/collStats
description: |
Returns statistics regarding a collection or view.
---
name: :pipeline:`$project`
file: /reference/operator/aggregation/project
description: |
Expand Down
74 changes: 38 additions & 36 deletions source/reference/method/db.collection.stats.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Definition

.. include:: /includes/apiargs/method-db.collection.stats-options.rst

:returns: A :term:`document` that contains statistics on the specified
collection. See :dbcommand:`collStats` for a breakdown of the returned
:returns: A :term:`document` that contains statistics on the specified
collection. See :dbcommand:`collStats` for a breakdown of the returned
statistics.

The :method:`db.collection.stats()` method provides a wrapper
Expand All @@ -41,16 +41,16 @@ around the database command :dbcommand:`collStats`.
Behavior
--------

This method returns a JSON document with statistics related to the current
:program:`mongod` instance. Unless otherwise specified by the key name,
values related to size are displayed in bytes and can be overridden
This method returns a JSON document with statistics related to the current
:program:`mongod` instance. Unless otherwise specified by the key name,
values related to size are displayed in bytes and can be overridden
by ``scale``.

.. note::

The scale factor rounds values to whole numbers.

Depending on the storage engine, the data returned may differ. For details on
Depending on the storage engine, the data returned may differ. For details on
the fields, see :ref:`output details <collStats-output>`.

Accuracy after Unexpected Shutdown
Expand All @@ -64,7 +64,7 @@ Accuracy after Unexpected Shutdown
Index Filter Behavior
~~~~~~~~~~~~~~~~~~~~~

Filtering on ``indexDetails`` using either ``indexDetailsKey`` or
Filtering on ``indexDetails`` using either ``indexDetailsKey`` or
``indexDetailsName`` will only return a single matching index.
If no exact match is found, ``indexDetails`` will show information
on all indexes for the collection.
Expand All @@ -74,9 +74,9 @@ The ``indexDetailsKey`` field takes a document of the following form:
.. code-block:: javascript

{ '<string>' : <value>, '<string>' : <value>, ... }
Where ``<string>>`` is the field that is indexed and ``<value>`` is either
the direction of the index, or the special index type such as ``text`` or

Where ``<string>>`` is the field that is indexed and ``<value>`` is either
the direction of the index, or the special index type such as ``text`` or
``2dsphere``. See :ref:`index types <index-types>` for the full list of
index types.

Expand All @@ -94,11 +94,11 @@ Examples
--------

.. note::
You can find the collection data used for these examples in our
`Getting Started Guide

You can find the collection data used for these examples in our
`Getting Started Guide
<https://docs.mongodb.org/getting-started/shell/import-data/>`_


Basic Stats Lookup
~~~~~~~~~~~~~~~~~~
Expand All @@ -108,7 +108,7 @@ The following operation returns stats on the ``restaurants`` collection:
.. code-block:: javascript

db.restaurants.stats()

The operation returns:

.. code-block:: javascript
Expand Down Expand Up @@ -247,8 +247,8 @@ The operation returns:
},
"ok" : 1
}
As stats was not give a scale parameter, all size values are in ``bytes``.

As stats was not give a scale parameter, all size values are in ``bytes``.


Stats Lookup With Scale
Expand All @@ -260,7 +260,7 @@ by specifying a ``scale`` of ``1024``:
.. code-block:: javascript

db.restaurants.stats( { scale : 1024 } )

The operation returns:

.. code-block:: javascript
Expand Down Expand Up @@ -295,7 +295,7 @@ information related to each of the indexes within the collection:
.. code-block:: javascript

db.restaurant.stats( { indexDetails : true } )

The operation returns:

.. code-block:: javascript
Expand Down Expand Up @@ -474,7 +474,7 @@ Statistics Lookup With Filtered Index Details

To filter the indexes in the :data:`~collStats.indexDetails` field, you can
either specify the index keys using the ``indexDetailsKey`` option or specify
the index name using the ``indexDetailsName``. To discover index keys and
the index name using the ``indexDetailsName``. To discover index keys and
names for the collection, use :method:`db.collection.getIndexes()`.

Given the following index:
Expand All @@ -491,34 +491,34 @@ Given the following index:
"name" : "borough_1_cuisine_1"
}

The following operation filters the ``indexDetails`` document to a single
The following operation filters the ``indexDetails`` document to a single
index as defined by the ``indexDetailsKey`` document.

.. code-block:: javascript

db.restaurants.stats(
{
'indexDetails' : true,
'indexDetailsKey' :
{
db.restaurants.stats(
{
'indexDetails' : true,
'indexDetailsKey' :
{
'borough' : 1,
'cuisine' : 1
}
}
'cuisine' : 1
}
}
)

The following operation filters the ``indexDetails`` document to a single
The following operation filters the ``indexDetails`` document to a single
index as defined by the ``indexDetailsName`` document.

.. code-block:: javascript

db.restaurants.stats(
{
'indexDetails' : true,
'indexDetailsName' : 'borough_1_cuisine_1'
}
db.restaurants.stats(
{
'indexDetails' : true,
'indexDetailsName' : 'borough_1_cuisine_1'
}
)

Both operations will return the same output:

.. code-block:: javascript
Expand Down Expand Up @@ -583,3 +583,5 @@ Both operations will return the same output:
}

For explanation of the output, see :ref:`output details<collStats-output>`.

.. seealso:: :pipeline:`$collStats`
Loading