Skip to content

Commit 336b130

Browse files
johnnyshieldsp
andauthored
MONGOID-5369 - Improvements to the Aggregation Pipeline doc page (#5330)
* MONGOID-5369 - Improvements to the Aggregation Pipeline doc page * Whitespace * adjust headings * restore this bit Co-authored-by: shields <[email protected]> Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent 06f13b0 commit 336b130

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

source/reference/aggregation.txt

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,23 @@ Aggregation Pipeline
1313
:class: singlecol
1414

1515

16-
Mongoid exposes MongoDB's `aggregation pipeline
17-
<https://mongodb.com/docs/manual/core/aggregation-pipeline/>`_ for queries
18-
involving multiple referenced associations at the same time. Given the
19-
following model definitions with referenced associations:
16+
Mongoid exposes `MongoDB's aggregation pipeline
17+
<https://www.mongodb.com/docs/manual/core/aggregation-pipeline/>`_,
18+
which is used to construct flows of operations that process and return results.
19+
The aggregation pipeline is a superset of the deprecated
20+
:ref:`map/reduce framework <map-reduce>` functionality.
21+
22+
23+
Basic Usage
24+
===========
25+
26+
.. _aggregation-pipeline-example-multiple-collections:
27+
28+
Querying Across Multiple Collections
29+
````````````````````````````````````
30+
31+
The aggregation pipeline may be used for queries involving multiple
32+
referenced associations at the same time:
2033

2134
.. code-block:: ruby
2235

@@ -45,22 +58,22 @@ could do the following:
4558
.. code-block:: ruby
4659

4760
band_ids = Band.collection.aggregate([
48-
{'$lookup' => {
61+
{ '$lookup' => {
4962
from: 'tours',
5063
localField: '_id',
5164
foreignField: 'band_id',
5265
as: 'tours',
53-
}},
54-
{'$lookup' => {
66+
} },
67+
{ '$lookup' => {
5568
from: 'awards',
5669
localField: '_id',
5770
foreignField: 'band_id',
5871
as: 'awards',
59-
}},
60-
{'$match' => {
72+
} },
73+
{ '$match' => {
6174
'tours.year' => {'$gte' => 2000},
6275
'awards._id' => {'$exists' => true},
63-
}},
76+
} },
6477
{'$project' => {_id: 1}},
6578
])
6679
bands = Band.find(band_ids)
@@ -77,7 +90,7 @@ having to send the list of document ids to Mongoid in the second query
7790
.. _aggregation-pipeline-builder-dsl:
7891

7992
Builder DSL
80-
-----------
93+
===========
8194

8295
Mongoid provides limited support for constructing the aggregation pipeline
8396
itself using a high-level DSL. The following aggregation pipeline operators
@@ -113,7 +126,7 @@ For example, given the following models:
113126
field :name, type: String
114127
end
115128

116-
We could find out which states a participant visited:
129+
We can find out which states a participant visited:
117130

118131
.. code-block:: ruby
119132

source/working-with-data.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Working With Data
1212
reference/crud
1313
reference/queries
1414
reference/text-search
15+
reference/aggregation
1516
reference/map-reduce
1617
reference/persistence-configuration
1718
reference/nested-attributes

0 commit comments

Comments
 (0)