@@ -21,12 +21,16 @@ results. You can use aggregation operations to:
21
21
22
22
To perform aggregation operations, you can use:
23
23
24
- - :ref:`Aggregation pipelines <aggregation-framework>`
24
+ - :ref:`Aggregation pipelines <aggregation-framework>`, which are the
25
+ preferred method for performing aggregations.
25
26
26
27
- :ref:`Single purpose aggregation methods
27
- <single-purpose-agg-operations>`
28
+ <single-purpose-agg-methods>`, which are simple but lack the
29
+ capabilities of an aggregation pipeline.
28
30
29
- - :ref:`Map-reduce functions <aggregation-map-reduce>`
31
+ - :ref:`Map-reduce operations <aggregation-map-reduce>`, which are
32
+ deprecated starting in MongoDB 5.0. Instead, use an aggregation
33
+ pipeline.
30
34
31
35
.. _aggregation-framework:
32
36
@@ -40,50 +44,39 @@ Aggregation Pipeline Example
40
44
41
45
.. include:: /includes/aggregation-pipeline-example.rst
42
46
43
- For a runnable example, see :ref:`Complete Aggregation Pipeline
44
- Example <aggregation-pipeline-example>`.
47
+ For runnable examples containing sample input documents, see
48
+ :ref:`Complete Aggregation Pipeline Examples
49
+ <aggregation-pipeline-examples>`.
45
50
46
- Aggregation Pipeline Stages and Operations
47
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51
+ .. _single-purpose-agg-methods:
48
52
49
- The most basic pipeline stages provide *filters* that operate like
50
- queries and *document transformations* that modify the form
51
- of the output document.
53
+ Single Purpose Aggregation Methods
54
+ ----------------------------------
52
55
53
- Other pipeline operations provide tools for grouping and sorting
54
- documents by specific field or fields as well as tools for aggregating
55
- the contents of arrays, including arrays of documents. In addition,
56
- pipeline stages can use :ref:`operators
57
- <aggregation-expression-operators>` for tasks such as calculating the
58
- average or concatenating a string.
56
+ You can use the following single purpose aggregation methods to
57
+ aggregate documents from a single collection:
59
58
60
- The pipeline provides efficient data aggregation using native
61
- operations within MongoDB, and is the preferred method for data
62
- aggregation in MongoDB.
59
+ .. list-table::
60
+ :header-rows: 1
61
+ :widths: 50 50
62
+
63
+ * - Method
64
+ - Description
63
65
64
- The aggregation pipeline can operate on a
65
- :doc:`sharded collection </sharding>`.
66
+ * - :method:`db.collection.estimatedDocumentCount()`
67
+ - Returns an approximate count of the documents in a collection or
68
+ a view.
66
69
67
- The aggregation pipeline can use indexes to improve its performance
68
- during some of its stages. In addition, the aggregation pipeline has an
69
- internal optimization phase. See
70
- :ref:`aggregation-pipeline-operators-and-performance` and
71
- :doc:`/core/aggregation-pipeline-optimization` for details.
70
+ * - :method:`db.collection.count()`
71
+ - Returns a count of the number of documents in a collection or a
72
+ view.
72
73
73
- .. _single-purpose-agg-operations:
74
+ * - :method:`db.collection.distinct()`
75
+ - Returns an array of documents that have distinct values for the
76
+ specified field.
74
77
75
- Single Purpose Aggregation Operations
76
- -------------------------------------
77
-
78
- MongoDB also provides :method:`db.collection.estimatedDocumentCount()`,
79
- :method:`db.collection.count()` and :method:`db.collection.distinct()`.
80
-
81
- All of these operations aggregate documents from a single collection.
82
- While these operations provide simple access to common aggregation
83
- processes, they lack the flexibility and capabilities of an aggregation
84
- pipeline.
85
-
86
- .. include:: /images/distinct.rst
78
+ The single purpose aggregation methods are simple but lack the
79
+ capabilities of an :ref:`aggregation pipeline <aggregation-framework>`.
87
80
88
81
.. _aggregation-map-reduce:
89
82
@@ -92,21 +85,22 @@ Map-Reduce
92
85
93
86
.. include:: /includes/fact-use-aggregation-not-map-reduce.rst
94
87
95
- Additional Features and Behaviors
96
- ---------------------------------
97
-
98
- For a feature comparison of the aggregation pipeline,
99
- map-reduce, and the special group functionality, see
88
+ For a feature comparison of aggregation pipelines and map-reduce, see
100
89
:doc:`/reference/aggregation-commands-comparison`.
101
90
102
91
Learn More
103
92
----------
104
93
105
- Practical MongoDB Aggregations E-Book
106
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
94
+ To learn more about aggregations, see:
95
+
96
+ - :ref:`aggregation-pipeline`
97
+
98
+ - :ref:`aggregation-expression-operators`
99
+
100
+ - :ref:`aggregation-pipeline-operator-reference`
107
101
108
- For more information on aggregations, read the `Practical MongoDB
109
- Aggregations <https://www.practical-mongodb-aggregations.com>`__ e-book.
102
+ - `Practical MongoDB Aggregations
103
+ <https://www.practical-mongodb-aggregations.com>`_
110
104
111
105
112
106
.. toctree::
0 commit comments