@@ -51,27 +51,29 @@ value of ``Kayden Washington``.
51
51
.. code-block:: javascript
52
52
:copyable: false
53
53
54
- @MongoDB /query find a document in the users collection with the name
55
- of Kayden Washington.
54
+ @MongoDB /query In the sample_mflix database, find a document in the
55
+ users collection with the name of Kayden Washington.
56
56
57
57
The Github Copilot Chat uses the |copilot| to
58
58
generate the following query using knowledge of your database schema:
59
59
60
60
.. code-block:: javascript
61
61
62
+ use(`sample_mflix`);
62
63
db.getCollection('users').findOne({ name: 'Kayden Washington' });
63
64
64
65
Once the |copilot| generates the query, you can choose to run the query
65
66
directly or open the query in a playground.
66
67
67
- .. figure:: /images/copilot-query.png
68
- :figwidth: 700px
69
- :alt: Image copilot generating a query
68
+ .. figure:: /images/copilot-query.png
69
+ :figwidth: 700px
70
+ :alt: Screenshot of copilot generating a query
70
71
71
72
Build an Aggregation Pipeline
72
73
`````````````````````````````
73
74
74
- You can also use the |copilot| to build aggregation pipelines. Consider the ``users`` collection in the `Mflix Sample Database
75
+ You can also use the |copilot| to build aggregation pipelines. Consider
76
+ the ``users`` collection in the `Mflix Sample Database
75
77
<https://www.mongodb.com/docs/atlas/sample-data/sample-mflix/#sample_mflix.users>`__.
76
78
Each document in the collection has the following structure:
77
79
@@ -101,13 +103,19 @@ The |copilot| generates the following aggregation pipeline:
101
103
102
104
.. code-block:: javascript
103
105
106
+ use('sample_mflix');
104
107
db.getCollection('users').aggregate([
105
- // First stage: Sort documents alphabetically by name
106
108
{ $sort: { name: 1 } },
107
- // Second stage: Remove the password field from each document
108
- { $unset: "password" }
109
+ { $project: { password: 0 } }
109
110
]);
110
111
112
+ Once the |copilot| generates the query, you can choose to run the pipeline
113
+ directly or open the pipeline in a playground.
114
+
115
+ .. figure:: /images/copilot-agg-pipeline.png
116
+ :figwidth: 700px
117
+ :alt: Screenshot of copilot generating an aggregation pipeline
118
+
111
119
You can also iteratively build on your aggregation pipeline:
112
120
113
121
.. code-block:: javascript
@@ -121,11 +129,13 @@ The |copilot| returns the following aggregation pipeline:
121
129
122
130
.. code-block:: javascript
123
131
132
+ use('sample_mflix');
124
133
db.getCollection('users').aggregate([
125
134
{ $sort: { name: 1 } },
126
135
{ $project: { password: 0 } },
127
- { $addFields:
128
- { username: { $arrayElemAt:
129
- [{ $split: ["$email", "@"] }, 0] } } },
130
- { $out: "sortedUsersWithUsernames" }
136
+ { $addFields: { username: { $arrayElemAt: [{ $split: ["$email", "@"] }, 0] } } }
131
137
]);
138
+
139
+ .. figure:: /images/copilot-agg-pipeline2.png
140
+ :figwidth: 700px
141
+ :alt: Screenshot of copilot iteratively building on an aggregation pipeline
0 commit comments