55Aggregation
66===========
77
8+ .. facet::
9+ :name: genre
10+ :values: reference
11+
812.. meta::
13+ :keywords: node.js, code example, runnable app
914 :description: Learn to use aggregation operations in the MongoDB Node.js Driver to create pipelines for data transformation and summarization.
1015
1116.. contents:: On this page
@@ -14,6 +19,14 @@ Aggregation
1419 :depth: 2
1520 :class: singlecol
1621
22+ .. toctree::
23+
24+ Filtered Subset </aggregation/filtered-subset/>
25+ Group & Total </aggregation/group-total/>
26+ Unpack Arrays & Group </aggregation/unpack-arrays/>
27+ One-to-One Join </aggregation/one-to-one-join/>
28+ Multi-Field Join </aggregation/multi-field-join/>
29+
1730.. _nodejs-aggregation-overview:
1831
1932Overview
@@ -101,7 +114,7 @@ database:
101114
102115.. tip::
103116
104- For more information on connecting to your MongoDB deployment, see the :doc:`Connection Guide </fundamentals/connection >`.
117+ For more information on connecting to your MongoDB deployment, see the :doc:`Connection Guide </connect >`.
105118
106119Aggregation Example
107120~~~~~~~~~~~~~~~~~~~
@@ -134,6 +147,106 @@ This example produces the following output:
134147
135148For more information, see the `aggregate() API documentation <{+api+}/classes/Collection.html#aggregate>`__.
136149
150+ .. _node-aggregation-tutorials-landing:
151+ .. _node-aggregation-tutorials:
152+
153+ Aggregation Tutorials
154+ ---------------------
155+
156+ Aggregation tutorials provide detailed explanations of common
157+ aggregation tasks in a step-by-step format. The tutorials are adapted
158+ from examples in the `Practical MongoDB Aggregations book
159+ <https://www.practical-mongodb-aggregations.com/>`__ by Paul Done.
160+
161+ Each tutorial includes the following sections:
162+
163+ - **Introduction**, which describes the purpose and common use cases of the
164+ aggregation type. This section also describes the example and desired
165+ outcome that the tutorial demonstrates.
166+
167+ - **Before You Get Started**, which describes the necessary databases,
168+ collections, and sample data that you must have before building the
169+ aggregation pipeline and performing the aggregation.
170+
171+ - **Tutorial**, which describes how to build and run the aggregation
172+ pipeline. This section describes each stage of the completed
173+ aggregation tutorial, and then explains how to run and interpret the
174+ output of the aggregation.
175+
176+ At the end of each aggregation tutorial, you can find a link to a fully
177+ runnable Node.js code file that you can run in your environment.
178+
179+ .. tip::
180+
181+ To learn more about performing aggregations, see the
182+ :ref:`node-aggregation` guide.
183+
184+ .. _node-agg-tutorial-template-app:
185+
186+ Aggregation Template App
187+ ~~~~~~~~~~~~~~~~~~~~~~~~
188+
189+ Before you begin following an aggregation tutorial, you must set up a
190+ new Node.js app. You can use this app to connect to a MongoDB
191+ deployment, insert sample data into MongoDB, and run the aggregation
192+ pipeline in each tutorial.
193+
194+ .. tip::
195+
196+ To learn how to install the driver and connect to MongoDB,
197+ see the :ref:`node-get-started-download-and-install` and
198+ :ref:`node-get-started-create-deployment` steps of the
199+ Quick Start guide.
200+
201+ Once you install the driver, create a file called
202+ ``agg_tutorial.js``. Paste the following code in this file to create an
203+ app template for the aggregation tutorials:
204+
205+ .. literalinclude:: /includes/aggregation/template-app.js
206+ :language: javascript
207+ :copyable: true
208+
209+ .. important::
210+
211+ In the preceding code, read the code comments to find the sections of
212+ the code that you must modify for the tutorial you are following.
213+
214+ If you attempt to run the code without making any changes, you will
215+ encounter a connection error.
216+
217+ For every tutorial, you must replace the connection string placeholder with
218+ your deployment's connection string.
219+
220+ .. tip::
221+
222+ To learn how to locate your deployment's connection string, see the
223+ :ref:`node-get-started-connection-string` step of the Quick Start guide.
224+
225+ For example, if your connection string is
226+ ``"mongodb+srv://mongodb-example:27017"``, your connection string assignment resembles
227+ the following:
228+
229+ .. code-block:: javascript
230+ :copyable: false
231+
232+ const uri = "mongodb+srv://mongodb-example:27017";
233+
234+ To run the completed file after you modify the template for a
235+ tutorial, run the following command in your shell:
236+
237+ .. code-block:: bash
238+
239+ node agg_tutorial.js
240+
241+ Available Tutorials
242+ ~~~~~~~~~~~~~~~~~~~
243+
244+ - :ref:`node-aggregation-filtered-subset`
245+ - :ref:`node-aggregation-group-total`
246+ - :ref:`node-aggregation-arrays`
247+ - :ref:`node-aggregation-one-to-one`
248+ - :ref:`node-aggregation-multi-field`
249+
137250Additional Examples
138251~~~~~~~~~~~~~~~~~~~
139252
0 commit comments