Skip to content

Commit 5275d65

Browse files
committed
DOCSP-50497 define framework with no concrete example, save for server pages
1 parent 2c34f85 commit 5275d65

File tree

2 files changed

+15
-48
lines changed

2 files changed

+15
-48
lines changed

source/aggregation/pipeline-stages.txt

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,53 +22,33 @@ Overview
2222
------------
2323

2424
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+}.
2626

2727
Build 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

6747
Aggregation Stage Methods
6848
-------------------------
6949

7050
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
7252
stage and see a code example in a Node.js application, follow the link from the
7353
stage name to its reference page in the {+mdb-server+} manual.
7454

source/code-snippets/aggregation/agg.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,11 @@ async function run() {
1010
const db = client.db("aggregation");
1111
const coll = db.collection("restaurants");
1212

13-
// Create sample documents
14-
const docs = [
15-
{ stars: 3, categories: ["Bakery", "Sandwiches"], name: "Rising Sun Bakery" },
16-
{ stars: 4, categories: ["Bakery", "Cafe", "Bar"], name: "Cafe au Late" },
17-
{ stars: 5, categories: ["Coffee", "Bakery"], name: "Liz's Coffee Bar" },
18-
{ stars: 3, categories: ["Steak", "Seafood"], name: "Oak Steakhouse" },
19-
{ stars: 4, categories: ["Bakery", "Dessert"], name: "Petit Cookie" },
20-
];
21-
22-
// Insert documents into the restaurants collection
23-
const result = await coll.insertMany(docs);
24-
// end data insertion
25-
2613
// begin aggregation
2714
// Define an aggregation pipeline with a match stage and a group stage
2815
const pipeline = [
29-
{ $match: { categories: "Bakery" } },
30-
{ $group: { _id: "$stars", count: { $sum: 1 } } }
16+
{ $match: { cuisine: "Bakery" } },
17+
{ $group: { _id: "$borough", count: { $sum: 1 } } }
3118
];
3219

3320
// Execute the aggregation

0 commit comments

Comments
 (0)