Skip to content

Commit 1ebb8ce

Browse files
committed
DOCSP-43493 adding agg pipeline example
1 parent 824ff26 commit 1ebb8ce

File tree

3 files changed

+130
-44
lines changed

3 files changed

+130
-44
lines changed

snooty.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ cifs = ":abbr:`CIFS (Common Internet File System)`"
4141
cps = ":abbr:`CPS (Cloud Provider Snapshots)`"
4242
cmk = ":abbr:`CMK (customer master key)`"
4343
compass = "MongoDB Compass"
44+
copilot = "MongoDB Github Copilot Participant"
4445
data-lakes = "Data Lakes"
4546
data-lake = "Data Lake"
4647
datadog = "`Datadog <https://www.datadoghq.com/>`__"

source/copilot-query.txt

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
.. _vsce-copilot-query:
2+
3+
==============
4+
/query Command
5+
==============
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
The ``/query`` command assists in generating queries from a natural
16+
language against a connected MongoDB cluster. The MongoDB Github Copilot
17+
Participant provides underlying schema information of the relevant
18+
collections to Github Copilot to generate a response. If you do not
19+
specify a collection in your prompt, the chat prompts you to select a
20+
relevant collection.
21+
22+
When the LLM generates a query, you can open the query in a playground
23+
file or run the query directly in your collection.
24+
25+
Examples
26+
~~~~~~~~
27+
28+
Generate a Query
29+
````````````````
30+
31+
Consider the ``users`` collection in the `Mflix Sample Database
32+
<https://www.mongodb.com/docs/atlas/sample-data/sample-mflix/#sample_mflix.users>`__.
33+
Each document in the collection has the following structure:
34+
35+
.. code-block:: javascript
36+
:copyable: false
37+
38+
{
39+
_id: {
40+
"$oid": "59b99db4cfa9a34dcd7885b6"
41+
},
42+
name: "Kayden Washington",
43+
44+
password: "11222021"
45+
}
46+
47+
Once you connect to the deployment that contains the ``users``
48+
collection, you can ask the Github Copilot chat to generate a query that
49+
finds the document in the ``users`` collection that has the ``name``
50+
value of `` "Kayden Washington"``.
51+
52+
.. code-block:: javascript
53+
:copyable: false
54+
55+
@MongoDB /query find a document in the users collection with the name
56+
of Kayden Washington.
57+
58+
The Github Copilot Chat uses the MongoDB Github Copilot Participant to
59+
generate the following query using knowledge of your database schema:
60+
61+
.. code-block:: javascript
62+
63+
db.getCollection('users').findOne({ name: 'Kayden Washington' });
64+
65+
Once the MongoDB Github Copilot Participant generates the query, you can choose to run the query directly or open the query in a playground.
66+
67+
Build an Aggregation Pipeline
68+
`````````````````````````````
69+
70+
Consider the ``users`` collection in the `Mflix Sample Database
71+
<https://www.mongodb.com/docs/atlas/sample-data/sample-mflix/#sample_mflix.users>`__.
72+
Each document in the collection has the following structure:
73+
74+
.. code-block:: javascript
75+
:copyable: false
76+
77+
{
78+
_id: {
79+
"$oid": "59b99db4cfa9a34dcd7885b6"
80+
},
81+
name: "Kayden Washington",
82+
83+
password: "11222021"
84+
}
85+
86+
Once you connect to the deployment that contains the ``users``
87+
collection, you can ask the Github Copilot chat to generate an aggregation pipeline.
88+
89+
.. code-block:: javascript
90+
:copyable: false
91+
92+
@MongoDB /query Generate an aggregation pipeline on the users collection that first sorts documents alphabetically by name and then removes the password field from each document.
93+
94+
The |copilot| generates the following aggregation pipeline:
95+
96+
.. code-block:: javascript
97+
98+
db.getCollection('users').aggregate([
99+
// First stage: Sort documents alphabetically by name
100+
{ $sort: { name: 1 } },
101+
// Second stage: Remove the password field from each document
102+
{ $unset: "password" }
103+
]);
104+
105+
You can also iteratively build on your aggregation pipeline.
106+
107+
.. code-block:: javascript
108+
:copyable: false
109+
110+
@MongoDB /query Add a stage to my pipeline that adds a username field ot each document containing the user's email username without the email domain.
111+
112+
The |copilot| returns the following aggregation pipeline:
113+
114+
.. code-block:: javascript
115+
116+
db.getCollection('users').aggregate([
117+
{ $sort: { name: 1 } },
118+
{ $project: { password: 0 } },
119+
{ $addFields:
120+
{ username: { $arrayElemAt:
121+
[{ $split: ["$email", "@"] }, 0] } } },
122+
{ $out: "sortedUsersWithUsernames" }
123+
]);

source/copilot.txt

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ MongoDB Github Copilot Participant
1212
:depth: 1
1313
:class: singlecol
1414

15-
1615
|vsce-full| includes a MongoDB Github Copilot Participant to assist in
1716
using `Github Copilot <https://github.com/features/copilot>`__ with your
1817
MongoDB deployments. Through Github Copilot's chat feature, users with
@@ -25,59 +24,22 @@ documentation.
2524
The MongoDB Github Copilot Participant includes MongoDB-specific
2625
commands to assist in interacting with your deployment.
2726

27+
Commands
28+
--------
29+
2830
/query
29-
------
31+
~~~~~~
3032

3133
The ``/query`` command assists in generating queries from a natural
32-
language against a connected MongoDB cluster. The MongoDB Github Copilot
33-
Participant provides underlying schema information of the relevant
34-
collections to Github Copilot to generate a response. If you do not
35-
specify a collection in your prompt, the chat prompts you to select a
36-
relevant collection.
37-
38-
When the LLM generates a query, you can open the query in a playground
39-
file or run the query directly in your collection.
40-
41-
Example
42-
~~~~~~~
43-
44-
Consider the ``users`` collection in the `Mflix Sample Database
45-
<https://www.mongodb.com/docs/atlas/sample-data/sample-mflix/#sample_mflix.users>`__.
46-
Each document in the collection has the following structure:
47-
48-
.. code-block:: javascript
49-
:copyable: false
50-
51-
{
52-
_id: {
53-
"$oid": "59b99db4cfa9a34dcd7885b6"
54-
},
55-
name: "Kayden Washington",
56-
57-
password: "11222021"
58-
}
59-
Once you connect to the deployment that contains the ``users``
60-
collection, you can ask the Github Copilot chat to generate a query that
61-
finds the document in the ``users`` collection that has the ``name``
62-
value of `` "Kayden Washington"``.
63-
64-
.. code-block:: javascript
65-
:copyable: false
66-
67-
@MongoDB /query find a document in the users collection with the name
68-
of Kayden Washington.
34+
language against a connected MongoDB cluster.
6935

70-
The Github Copilot Chat uses the MongoDB Github Copilot Participant to
71-
generate the following query using knowledge of your database schema:
7236

73-
.. code-block:: javascript
74-
75-
db.getCollection('users').findOne({ name: 'Kayden Washington' });
7637

7738

7839
.. toctree::
7940
:titlesonly:
8041

42+
/query </copilot-query>
8143
AI & Data Usage </ai-data-usage>
8244

8345

0 commit comments

Comments
 (0)