@@ -22,53 +22,33 @@ Overview
22
22
------------
23
23
24
24
On this page, you can learn how to create an aggregation pipeline and pipeline
25
- stages by using methods in the Node.js Driver .
25
+ stages by using methods in the {+driver-short+} .
26
26
27
27
Build an Aggregation Pipeline
28
28
-----------------------------
29
29
30
- You can use the {+driver-short+} to build an aggregation pipeline by INSERT
31
- HERE. See the following sections to learn more about each of these approaches.
30
+ You can use the {+driver-short+} to build an aggregation pipeline by adding
31
+ aggregation stages and operations to the aggregation framework. See the
32
+ following code to learn how to format the framework.
32
33
33
- .. note::
34
- ..
35
- This example uses the ``sample_restaurants.restaurants`` collection
36
- from the :atlas:`Atlas sample datasets </sample-data>`. To learn how to create a
37
- free MongoDB Atlas cluster and load the sample datasets, see the :ref:`Get Started <node-get-started>` guide.
38
34
39
- The following code example produces a count of the number of bakeries in each borough
40
- of New York City. To do so, the aggregation pipeline uses the following aggregation stages:
35
+ .. code-block:: javascript
41
36
42
- - A :manual:`$match </reference/operator/aggregation/match/>` stage to filter
43
- for documents whose ``cuisine`` field contains the element ``Bakery``.
44
- - A :manual:`$group </reference/operator/aggregation/group/>` stage to group the
45
- matching documents by the ``borough`` field, accumulating a count of documents
46
- for each distinct value in the ``borough`` field.
37
+ // Defines the aggregation pipeline
38
+ const pipeline = [
39
+ { $match: { ... } },
40
+ { $group: { ... } }
41
+ ];
47
42
48
- .. literalinclude:: /code-snippets/aggregation/agg.js
49
- :start-after: begin aggregation
50
- :end-before: end aggregation
51
- :language: javascript
52
- :dedent:
53
-
54
- This example produces the following output:
55
-
56
- .. code-block:: json
57
- :copyable: false
58
-
59
- { _id = 'Bronx', count = 71 }
60
- { _id = 'Brooklyn', count = 173 }
61
- { _id = 'Staten Island', count = 20 }
62
- { _id = 'Missing', count = 2 }
63
- { _id = 'Manhattan', count = 221 }
64
- { _id = 'Queens', count = 204 }
43
+ // Executes the aggregation pipeline
44
+ const results = coll.aggregate(pipeline);
65
45
66
46
67
47
Aggregation Stage Methods
68
48
-------------------------
69
49
70
50
The following table lists the stages in the aggregation pipeline. The methods
71
- retain the same name when used in Node.js. To learn more about an aggregation
51
+ are formatted as they are listed when used in Node.js. To learn more about an aggregation
72
52
stage and see a code example in a Node.js application, follow the link from the
73
53
stage name to its reference page in the {+mdb-server+} manual.
74
54
0 commit comments