Skip to content

Commit f075ef3

Browse files
(DOCSP-6082): Updating agg pipeline builder for 1.19 (#148)
* (DOCSP-6082): Updating agg pipeline builder for 1.19 * Updates per Rob's feedback * typo fix * formatting fix
1 parent d73e75c commit f075ef3

11 files changed

+185
-160
lines changed

source/aggregation-pipeline-builder.txt

Lines changed: 170 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -44,173 +44,233 @@ Create an Aggregation Pipeline
4444

4545
.. include:: /includes/steps/create-agg-pipeline.rst
4646

47+
Specify Custom Collation
48+
~~~~~~~~~~~~~~~~~~~~~~~~
49+
50+
Use :manual:`custom collation </reference/collation/>` to specify
51+
language-specific rules for string comparison, such as rules for
52+
letter case and accent marks.
53+
54+
To specify a custom collation:
55+
56+
1. Click the :guilabel:`Collation` button at the top of the pipeline
57+
builder.
58+
59+
#. Enter your collation document.
60+
61+
Limitations
62+
~~~~~~~~~~~
63+
64+
The :pipeline:`$out` stage is not available if you are connected to a
65+
`Data Lake <https://www.mongodb.com/atlas/data-lake>`__.
66+
4767
.. _save-agg-pipeline:
4868

4969
Save a Pipeline
5070
---------------
5171

52-
To save a pipeline:
72+
You can save your pipeline so it can be reloaded into
73+
the pipeline builder in the future. You can also create a
74+
:manual:`view </core/views/>` from the results of your pipeline.
5375

54-
1. Name your pipeline using the
55-
:guilabel:`Enter a pipeline name` input at the top of the
56-
:guilabel:`Aggregations` view.
76+
To save your pipeline:
5777

58-
2. Click :guilabel:`Save Pipeline`.
78+
1. Click the :guilabel:`Save` button at the top of the pipeline
79+
builder.
5980

60-
.. _open-saved-pipeline:
81+
#. Enter a name for your pipeline.
6182

62-
Open a Saved Pipeline
63-
---------------------
83+
#. Click :guilabel:`Save`.
6484

65-
.. important::
85+
Create a View from Pipeline Results
86+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6687

67-
Opening a saved pipeline abandons any unsaved changes to the
68-
pipeline you are currently working on. If the circle at the
69-
top-right of the :guilabel:`Aggregations` view is orange, this
70-
means you have unsaved changes to your pipeline.
88+
.. note::
7189

72-
To open a previously saved pipeline:
90+
Creating a view from pipeline results does not save the pipeline
91+
itself.
7392

74-
1. Click the :guilabel:`Folder` icon to the left of the pipeline name
75-
input.
93+
To create a view from your pipeline results:
7694

77-
2. Hover over the pipeline you want to open and click :guilabel:`Open`.
95+
1. Click the arrow next to the :guilabel:`Save` button at the top
96+
of the pipeline builder.
7897

79-
3. In the ensuing dialog, click :guilabel:`Open Pipeline`.
98+
#. Click :guilabel:`Create a View`.
8099

81-
Additional Pipeline Options
82-
---------------------------
100+
#. Enter a name for your view.
83101

84-
Click the :guilabel:`...` button to the right of the
85-
:guilabel:`Save Pipeline` button to access additional pipeline
86-
options:
102+
#. Click :guilabel:`Create`.
87103

88-
.. figure:: /images/compass/agg-builder-export-dropdown.png
89-
:alt: Aggregation Builder additional pipeline options
104+
|compass-short| creates a view from your pipeline results in the same
105+
database where the pipeline was created.
90106

91-
The following additional options are available:
107+
.. _open-saved-pipeline:
92108

93-
.. list-table::
94-
:header-rows: 1
95-
:widths: 30 70
109+
Open a Saved Pipeline
110+
---------------------
96111

97-
* - Option
98-
- Description
99-
* - Export to Language
100-
- Format and export the current pipeline in the selected language.
101-
The languages currently supported are Java, Node, C#, and
102-
Python 3. For more information, see
103-
:ref:`Export Pipeline to Specific Langague
104-
<compass-export-pipeline>`.
105-
* - Clone Pipeline
106-
- Creates a new version of the current pipeline by appending
107-
``(copy)`` to the current pipeline name, retaining the current
108-
pipeline state. This allows you to modify and save a new version
109-
of the pipeline.
110-
* - New Pipeline
111-
- Resets the pipeline to its initial state.
112-
113-
.. important::
114-
115-
The :guilabel:`New Pipeline` option does not save your
116-
current pipeline state. If you wish to
117-
:ref:`save your current pipeline <save-agg-pipeline>`, you
118-
must do so before selecting this option.
119-
120-
If the circle at the top-right of the :guilabel:`Aggregations` view
121-
is orange, this means you have unsaved changes to your pipeline.
122-
123-
The following toggles provide additional pipeline options:
112+
1. Click the :guilabel:`Folder` icon at the top left of the
113+
pipeline builder.
114+
115+
#. Hover over the pipeline you want to open and click :guilabel:`Open`.
116+
117+
#. In the modal, click :guilabel:`Open Pipeline`.
118+
119+
Pipeline Options
120+
----------------
121+
122+
The toggles at the top of the pipeline builder control the
123+
following options:
124124

125125
.. list-table::
126126
:header-rows: 1
127127
:widths: 30 70
128128

129129
* - Option
130130
- Description
131-
* - Comment Mode
132-
- When enabled, adds helper comments to each stage.
133-
* - Sample Mode
134-
- (*Recommended*) When enabled, limits input documents to ``100000``
135-
before :manual:`$group
136-
</reference/operator/aggregation/group/>`, :manual:`$bucket
137-
</reference/operator/aggregation/bucket/>`, and
138-
:manual:`$bucketAuto
139-
</reference/operator/aggregation/bucketAuto/>` stages.
140-
* - Auto Preview
131+
* - .. data:: Sample Mode
132+
- (*Recommended*) When enabled, limits input documents passed to
133+
:pipeline:`$group`, :pipeline:`$bucket`, and
134+
:pipeline:`$bucketAuto` stages. Set the document limit with the
135+
:data:`Limit` setting.
136+
137+
* - .. data:: Auto Preview
141138
- When enabled, |compass-short| automatically updates the
142139
preview documents pane to reflect the results of each active
143140
stage as the pipeline progresses.
144141

142+
Pipeline Settings
143+
~~~~~~~~~~~~~~~~~
144+
145+
To view and modify pipeline settings:
146+
147+
1. Click the gear icon at the top right of the pipeline builder to
148+
open the :guilabel:`Settings` panel.
149+
150+
#. Modify the pipeline settings. The following settings can be modified:
151+
152+
.. list-table::
153+
:header-rows: 1
154+
:widths: 30 70 30
155+
156+
* - Option
157+
- Description
158+
- Default
159+
* - .. data:: Comment Mode
160+
- When enabled, adds helper comments to each stage.
161+
- Enabled
162+
* - .. data:: Number of Preview Documents
163+
- Number of documents to show in the preview.
164+
- 20
165+
* - .. data:: Max Time
166+
- Cumulative time limit in milliseconds for processing
167+
the pipeline. Use this option to prevent long hang times.
168+
- 5000
169+
* - .. data:: Limit
170+
- When :guilabel:`Sample Mode` is enabled, number of documents
171+
passed to :pipeline:`$group`, :pipeline:`$bucket`, and
172+
:pipeline:`$bucketAuto` stages. Lower limits improve pipeline
173+
execution time, but may miss documents.
174+
- 100000
175+
176+
#. Click :guilabel:`Apply` to save changes and close the
177+
:guilabel:`Settings` panel.
178+
145179
Example
146180
-------
147181

148182
The following example walks through creating and executing a pipeline
149-
for a collection containing airline flight statistics.
183+
for a collection containing airline data. You can download this
184+
dataset from the following link:
185+
`air_airlines.json <https://raw.githubusercontent.com/mongodb/docs-assets/compass/air_airlines.json>`__.
186+
187+
For instructions on importing JSON data into your cluster, see
188+
:manual:`mongoimport </reference/program/mongoimport/>`. This
189+
procedure assumes you have the data in the
190+
``example.air_airlines`` namespace.
191+
150192

151193
Create the Pipeline
152194
~~~~~~~~~~~~~~~~~~~
153195

154196
The following pipeline has two aggregation stages:
155-
:manual:`$match </reference/operator/aggregation/match/>` and
156-
:manual:`$group </reference/operator/aggregation/group/>`. The
157-
``$match`` stage returns documents with ``carrierFsCode`` equal to
158-
``1I``, and the ``$group`` stage groups the documents returned from
159-
the previous stage by the ``departureAirportFsCode`` property:
197+
:pipeline:`$group` and :pipeline:`$match`.
198+
199+
- The ``$group`` stage groups documents by their
200+
``active`` status and ``country``. The stage also adds
201+
a new field called ``flightCount`` containing the number
202+
of documents in each group.
203+
204+
- The ``$match`` stage filters documents to only return
205+
those with a ``flightCount`` value greater than or
206+
equal to ``5``.
160207

161208
.. figure:: /images/compass/agg-builder-full-example.png
162209
:alt: Aggregation Builder Full Example
163210

164211
Copy the Pipeline to the Clipboard
165212
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
166213

167-
Using the :ref:`Export to Language <compass-export-pipeline>` feature,
168-
select :guilabel:`Node` and copy the pipeline into the clipboard:
214+
1. Click the :guilabel:`Export to Language` button at the top
215+
of the pipeline builder. The button opens the following modal:
169216

170-
.. figure:: /images/compass/agg-builder-example-export-to-node.png
171-
:alt: Aggregation Builder Full Example
217+
.. figure:: /images/compass/agg-builder-example-export-to-node.png
218+
:alt: Aggregation Builder Full Example
172219

173-
The aggregation pipeline syntax for Node applications is compatible
174-
with the :manual:`Mongo shell <mongo>`. The next step uses the Mongo
175-
shell to execute the pipeline, though you could also use a Node
176-
application with the `MongoDB NodeJS Driver
177-
<http://mongodb.github.io/node-mongodb-native/>`_ to achieve a similar
178-
result.
220+
#. Click the :guilabel:`Copy` button in the :guilabel:`My Pipeline`
221+
panel on the left. This button copies your pipeline to your
222+
clipboard in Mongo shell syntax. You will use the pipeline in the
223+
following section.
179224

180225
Execute the Pipeline
181226
~~~~~~~~~~~~~~~~~~~~
182227

183-
Launch and connect to a :manual:`mongod
184-
</reference/program/mongod/>` instance. Next, switch to the ``test``
185-
database where the ``flightStats`` collection exists:
186-
187-
.. code-block:: javascript
188-
189-
use test
190-
191-
The following command executes the pipeline created in |compass|:
192-
193-
.. code-block:: javascript
194-
195-
db.flightStats.aggregate([
196-
{
197-
$match: {
198-
carrierFsCode: "1I"
199-
}
200-
},
201-
{
202-
$group: {
203-
_id: "$departureAirportFsCode",
204-
flights: { $push: "$flightId" }
205-
}
206-
}
207-
])
208-
209-
The pipeline returns the following document:
228+
1. Launch and connect to a
229+
:manual:`mongod </reference/program/mongod/>` instance which contains the imported ``air_airlines.json`` dataset.
230+
231+
#. Switch to the ``example`` database where the ``air_airlines``
232+
collection exists:
233+
234+
.. code-block:: javascript
235+
236+
use example
237+
238+
#. Run the following command to execute the pipeline created in
239+
|compass-short|:
240+
241+
.. code-block:: javascript
242+
243+
db.air_airlines.aggregate([{
244+
$group: {
245+
_id: {
246+
active: '$active',
247+
country: '$country'
248+
},
249+
flightCount: {
250+
$sum: 1
251+
}
252+
}
253+
}, {
254+
$match: {
255+
flightCount: {
256+
$gte: 5
257+
}
258+
}
259+
}])
260+
261+
The following is an excerpt of the documents returned by
262+
the pipeline:
210263

211264
.. code-block:: javascript
212265

213-
{ "_id" : "EWR", "flights" : [ 543184347, 544589251, 544589200, 543183182, 545515483, 544595864 ] }
266+
{ "_id" : { "active" : "Y", "country" : "Nigeria" }, "flightCount" : 5 }
267+
{ "_id" : { "active" : "N", "country" : "Switzerland" }, "flightCount" : 46 }
268+
{ "_id" : { "active" : "N", "country" : "Bahrain" }, "flightCount" : 8 }
269+
{ "_id" : { "active" : "N", "country" : "Guinea-Bissau" }, "flightCount" : 8 }
270+
{ "_id" : { "active" : "N", "country" : "Argentina" }, "flightCount" : 14 }
271+
{ "_id" : { "active" : "N", "country" : "Moldova" }, "flightCount" : 17 }
272+
{ "_id" : { "active" : "Y", "country" : "Israel" }, "flightCount" : 6 }
273+
{ "_id" : { "active" : "N", "country" : "Finland" }, "flightCount" : 7 }
214274

215275
.. class:: hidden
216276

Loading
Loading
Loading
Loading
Loading
Loading

source/import-pipeline-from-text.txt

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,7 @@ pipeline.
3535
Procedure
3636
---------
3737

38-
.. important::
39-
40-
Importing a new pipeline abandons any unsaved changes to the
41-
pipeline you are currently working on. If the circle at the
42-
top-right of the :guilabel:`Aggregations` view is orange, this
43-
means you have unsaved changes to your pipeline.
44-
4538
.. include:: /includes/steps/import-pipeline-from-text.rst
4639

47-
Once you have imported your pipeline, if :guilabel:`Auto Preview` is
48-
enabled, the pipeline automatically executes. You can now modify
49-
individual stages of your pipeline, and see the results of those
50-
modifications reflected in the :guilabel:`Output` pane to the right
51-
of each respective stage.
40+
Once you import your pipeline, you can add and modify individual stages
41+
and see the results reflected in the :guilabel:`Output` of each respective stage.

0 commit comments

Comments
 (0)