@@ -22,53 +22,33 @@ Overview
2222------------
2323
2424On 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+} .
2626
2727Build an Aggregation Pipeline
2828-----------------------------
2929
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.
3233
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.
3834
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
4136
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+ ];
4742
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);
6545
6646
6747Aggregation Stage Methods
6848-------------------------
6949
7050The 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
7252stage and see a code example in a Node.js application, follow the link from the
7353stage name to its reference page in the {+mdb-server+} manual.
7454
0 commit comments