Skip to content

Commit ba92628

Browse files
committed
move agg tutorials
1 parent b773372 commit ba92628

File tree

9 files changed

+93
-130
lines changed

9 files changed

+93
-130
lines changed

config/redirects

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,12 @@ raw: ${prefix}/get-started/download-and-install/ -> ${base}/current/get-started/
7070
[*-master]: ${prefix}/${version}/indexes/wildcard-index/ -> ${base}/${version}/indexes/
7171
[*-master]: ${prefix}/${version}/indexes/clustered-index/ -> ${base}/${version}/indexes/
7272

73+
[*-master]: ${prefix}/${version}/aggregation/aggregation-tutorials/ -> ${base}/${version}/aggregation/
74+
[*-master]: ${prefix}/${version}/aggregation/aggregation-tutorials/filtered-subset/ -> ${base}/${version}/aggregation/filtered-subset/
75+
[*-master]: ${prefix}/${version}/aggregation/aggregation-tutorials/group-total/ -> ${base}/${version}/aggregation/group-total/
76+
[*-master]: ${prefix}/${version}/aggregation/aggregation-tutorials/multi-field-join/ -> ${base}/${version}/aggregation/multi-field-join/
77+
[*-master]: ${prefix}/${version}/aggregation/aggregation-tutorials/one-to-one-join/ -> ${base}/${version}/aggregation/one-to-one-join/
78+
[*-master]: ${prefix}/${version}/aggregation/aggregation-tutorials/unpack-arrays/ -> ${base}/${version}/aggregation/unpack-arrays/
79+
7380
# temp redirect until DOP deletes unversioned URLs
7481
[master]: ${prefix}/compatibility/ -> ${base}/current/compatibility/

source/aggregation.txt

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Transform Your Data with Aggregation
99
:values: reference
1010

1111
.. meta::
12-
:keywords: code example, transform, computed, pipeline
12+
:keywords: code example, transform, computed, pipeline, runnable app
1313
:description: Learn how to use {+driver-short+} to perform aggregation operations.
1414

1515
.. contents:: On this page
@@ -22,7 +22,11 @@ Transform Your Data with Aggregation
2222
:titlesonly:
2323
:maxdepth: 1
2424

25-
Tutorials </aggregation/aggregation-tutorials>
25+
Filtered Subset </aggregation/aggregation-tutorials/filtered-subset/>
26+
Group & Total </aggregation/aggregation-tutorials/group-total/>
27+
Unpack Arrays & Group </aggregation/aggregation-tutorials/unpack-arrays/>
28+
One-to-One Join </aggregation/aggregation-tutorials/one-to-one-join/>
29+
Multi-Field Join </aggregation/aggregation-tutorials/multi-field-join/>
2630

2731
Overview
2832
--------
@@ -254,7 +258,36 @@ Aggregation Tutorials
254258
~~~~~~~~~~~~~~~~~~~~~
255259

256260
To view step-by-step explanations of common aggregation tasks, see
257-
:ref:`pymongo-aggregation-tutorials-landing`.
261+
the following tutorials:
262+
263+
- :ref:`pymongo-aggregation-filtered-subset`
264+
- :ref:`pymongo-aggregation-group-total`
265+
- :ref:`pymongo-aggregation-arrays`
266+
- :ref:`pymongo-aggregation-one-to-one`
267+
- :ref:`pymongo-aggregation-multi-field`
268+
269+
Aggregation tutorials provide detailed explanations of common
270+
aggregation tasks in a step-by-step format. The tutorials are adapted
271+
from examples in the `Practical MongoDB Aggregations book
272+
<https://www.practical-mongodb-aggregations.com/>`__ by Paul Done.
273+
274+
Each tutorial includes the following sections:
275+
276+
- **Introduction**, which describes the purpose and common use cases of the
277+
aggregation type. This section also describes the example and desired
278+
outcome that the tutorial demonstrates.
279+
280+
- **Before You Get Started**, which describes the necessary databases,
281+
collections, and sample data that you must have before building the
282+
aggregation pipeline and performing the aggregation.
283+
284+
- **Tutorial**, which describes how to build and run the aggregation
285+
pipeline. This section describes each stage of the completed
286+
aggregation tutorial, and then explains how to run and interpret the
287+
output of the aggregation.
288+
289+
At the end of each aggregation tutorial, you can find a link to a fully
290+
runnable Python code file that you can run in your environment.
258291

259292
API Documentation
260293
~~~~~~~~~~~~~~~~~

source/aggregation/aggregation-tutorials.txt

Lines changed: 0 additions & 112 deletions
This file was deleted.

source/aggregation/aggregation-tutorials/filtered-subset.txt renamed to source/aggregation/filtered-subset.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ date of birth, vocation, and other details.
4242
Before You Get Started
4343
----------------------
4444

45-
Before you start this tutorial, complete the
46-
:ref:`pymongo-agg-tutorial-template-app` instructions to set up a working
47-
Python application.
45+
.. include:: /includes/aggregation-tutorial-intro.rst
4846

4947
After you set up the app, access the ``persons`` collection by adding the
5048
following code to the application:

source/aggregation/aggregation-tutorials/group-total.txt renamed to source/aggregation/group-total.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ only one customer, the order documents are grouped by the
4444
Before You Get Started
4545
----------------------
4646

47-
Before you start this tutorial, complete the
48-
:ref:`pymongo-agg-tutorial-template-app` instructions to set up a working
49-
Python application.
47+
.. include:: /includes/aggregation-tutorial-intro.rst
5048

5149
After you set up the app, access the ``orders`` collection by adding the
5250
following code to the application:

source/aggregation/aggregation-tutorials/multi-field-join.txt renamed to source/aggregation/multi-field-join.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ the ``orders`` collection.
6666
Before You Get Started
6767
----------------------
6868

69-
Before you start this tutorial, complete the
70-
:ref:`pymongo-agg-tutorial-template-app` instructions to set up a working
71-
Python application.
69+
.. include:: /includes/aggregation-tutorial-intro.rst
7270

7371
After you set up the app, access the ``products`` and ``orders``
7472
collections by adding the following code to the application:

source/aggregation/aggregation-tutorials/one-to-one-join.txt renamed to source/aggregation/one-to-one-join.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ that exists in documents in both collections.
6161
Before You Get Started
6262
----------------------
6363

64-
Before you start this tutorial, complete the
65-
:ref:`pymongo-agg-tutorial-template-app` instructions to set up a working
66-
Python application.
64+
.. include:: /includes/aggregation-tutorial-intro.rst
6765

6866
After you set up the app, access the ``orders`` and ``products``
6967
collections by adding the following code to the application:

source/aggregation/aggregation-tutorials/unpack-arrays.txt renamed to source/aggregation/unpack-arrays.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ into individual product order documents.
4646
Before You Get Started
4747
----------------------
4848

49-
Before you start this tutorial, complete the
50-
:ref:`pymongo-agg-tutorial-template-app` instructions to set up a working
51-
Python application.
49+
.. include:: /includes/aggregation-tutorial-intro.rst
5250

5351
After you set up the app, access the ``orders`` collection by adding the
5452
following code to the application:
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Before you begin following an aggregation tutorial, you must set up a
2+
new Python app. You can use this app to connect to a MongoDB
3+
deployment, insert sample data into MongoDB, and run the aggregation
4+
pipeline in each tutorial.
5+
6+
.. tip::
7+
8+
To learn how to install the driver and connect to MongoDB,
9+
see :ref:`pymongo-get-started`
10+
11+
Once you install the driver, create a file called
12+
``agg_tutorial.py``. Paste the following code in this file to create an
13+
app template for the aggregation tutorials:
14+
15+
.. literalinclude:: /includes/aggregation/template-app.py
16+
:language: python
17+
:copyable: true
18+
19+
.. important::
20+
21+
In the preceding code, read the code comments to find the sections of
22+
the code that you must modify for the tutorial you are following.
23+
24+
If you attempt to run the code without making any changes, you will
25+
encounter a connection error.
26+
27+
For every tutorial, you must replace the connection string placeholder with
28+
your deployment's connection string. To learn how to locate your deployment's connection
29+
string, see :ref:`pymongo-get-started-connection-string`.
30+
31+
For example, if your connection string is
32+
``"mongodb+srv://mongodb-example:27017"``, your connection string assignment resembles
33+
the following:
34+
35+
.. code-block:: python
36+
:copyable: false
37+
38+
uri = "mongodb+srv://mongodb-example:27017";
39+
40+
To run the completed file after you modify the template for a
41+
tutorial, run the following command in your shell:
42+
43+
.. code-block:: bash
44+
45+
python3 agg_tutorial.py

0 commit comments

Comments
 (0)