-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
aggregation.txt
105 lines (72 loc) · 2.66 KB
/
aggregation.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
.. _aggregation:
======================
Aggregation Operations
======================
.. default-domain:: mongodb
.. facet::
:name: genre
:values: reference
.. meta::
:keywords: sample dataset
:description: Aggregation operations process multiple documents and return computed results.
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Aggregation operations process multiple documents and return computed
results. You can use aggregation operations to:
- Group values from multiple documents together.
- Perform operations on the grouped data to return a single result.
- Analyze data changes over time.
To perform aggregation operations, you can use:
- :ref:`Aggregation pipelines <aggregation-pipeline-intro>`, which are
the preferred method for performing aggregations.
- :ref:`Single purpose aggregation methods
<single-purpose-agg-methods>`, which are simple but lack the
capabilities of an aggregation pipeline.
.. |page-topic| replace:: :atlas:`run aggregation pipelines in the UI </atlas-ui/agg-pipeline>`
.. cta-banner::
:url: https://www.mongodb.com/docs/atlas/atlas-ui/agg-pipeline
:icon: Cloud
.. include:: /includes/fact-atlas-compatible.rst
.. _aggregation-pipeline-intro:
Aggregation Pipelines
---------------------
.. include:: /includes/aggregation-pipeline-introduction.rst
Aggregation Pipeline Example
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. include:: /includes/aggregation-pipeline-example.rst
For runnable examples containing sample input documents, see
:ref:`Complete Aggregation Pipeline Examples
<aggregation-pipeline-examples>`.
Learn More About Aggregation Pipelines
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To learn more about aggregation pipelines, see
:ref:`aggregation-pipeline`.
.. _single-purpose-agg-methods:
Single Purpose Aggregation Methods
----------------------------------
The single purpose aggregation methods aggregate documents from a single
collection. The methods are simple but lack the capabilities of an
aggregation pipeline.
.. list-table::
:header-rows: 1
:widths: 50 50
* - Method
- Description
* - :method:`db.collection.estimatedDocumentCount()`
- Returns an approximate count of the documents in a collection or
a view.
* - :method:`db.collection.count()`
- Returns a count of the number of documents in a collection or a
view.
* - :method:`db.collection.distinct()`
- Returns an array of documents that have distinct values for the
specified field.
.. toctree::
:titlesonly:
:hidden:
Aggregation Pipeline </core/aggregation-pipeline>
Reference </reference/aggregation>
Map-Reduce </core/map-reduce>