Skip to content

Commit 303bc94

Browse files
DOCSP-1389 - Updates per Ravind's feedback
1 parent ac4c33a commit 303bc94

20 files changed

+146
-20
lines changed
48.9 KB
Loading
Loading
Loading
42.9 KB
Loading
Loading
Loading
33.4 KB
Loading

source/includes/driver-example-query-42.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,22 @@
2020

2121
.. include:: /includes/fact-mws.rst
2222

23+
- id: compass
24+
content: |
25+
.. code-block:: javascript
26+
27+
[
28+
{ item: "journal", status: "A", size: { h: 14, w: 21, uom: "cm" }, instock: [ { warehouse: "A", qty: 5 } ] },
29+
{ item: "notebook", status: "A", size: { h: 8.5, w: 11, uom: "in" }, instock: [ { warehouse: "C", qty: 5 } ] },
30+
{ item: "paper", status: "D", size: { h: 8.5, w: 11, uom: "in" }, instock: [ { warehouse: "A", qty: 60 } ] },
31+
{ item: "planner", status: "D", size: { h: 22.85, w: 30, uom: "cm" }, instock: [ { warehouse: "A", qty: 40 } ] },
32+
{ item: "postcard", status: "A", size: { h: 10, w: 15.25, uom: "cm" }, instock: [ { warehouse: "B", qty: 15 }, { warehouse: "C", qty: 35 } ] }
33+
]
34+
35+
For instructions on inserting documents in MongoDB Compass,
36+
see :doc:`Insert Documents </tutorial/insert-documents>`.
37+
38+
2339
- id: python
2440
content: |
2541
.. class:: copyable-code

source/includes/driver-example-query-43.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
99
db.inventory.find( { status: "A" } )
1010
11+
- id: compass
12+
content: |
13+
.. figure:: /images/compass-project-all-fields.png
14+
1115
- id: python
1216
content: |
1317
.. class:: copyable-code

source/includes/driver-example-query-44.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
99
db.inventory.find( { status: "A" }, { item: 1, status: 1 } )
1010
11+
- id: compass
12+
content: |
13+
.. figure:: /images/compass-project-specified-plus-id.png
14+
1115
- id: python
1216
content: |
1317
.. class:: copyable-code

source/includes/driver-example-query-45.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
99
db.inventory.find( { status: "A" }, { item: 1, status: 1, _id: 0 } )
1010
11+
- id: compass
12+
content: |
13+
.. figure:: /images/compass-project-suppress-id.png
14+
1115
- id: python
1216
content: |
1317
.. class:: copyable-code

source/includes/driver-example-query-46.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
99
db.inventory.find( { status: "A" }, { status: 0, instock: 0 } )
1010
11+
- id: compass
12+
content: |
13+
.. figure:: /images/compass-project-exclude-fields.png
14+
1115
- id: python
1216
content: |
1317
.. class:: copyable-code

source/includes/driver-example-query-47.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
{ item: 1, status: 1, "size.uom": 1 }
1212
)
1313
14+
- id: compass
15+
content: |
16+
.. figure:: /images/compass-project-embedded-fields.png
17+
1418
- id: python
1519
content: |
1620
.. class:: copyable-code

source/includes/driver-example-query-48.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
{ "size.uom": 0 }
1212
)
1313
14+
- id: compass
15+
content: |
16+
.. figure:: /images/compass-project-suppress-embedded-field.png
17+
1418
- id: python
1519
content: |
1620
.. class:: copyable-code

source/includes/driver-example-query-49.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
99
db.inventory.find( { status: "A" }, { item: 1, status: 1, "instock.qty": 1 } )
1010
11+
- id: compass
12+
content: |
13+
.. figure:: /images/compass-project-embedded-array-docs.png
14+
1115
- id: python
1216
content: |
1317
.. class:: copyable-code

source/includes/driver-example-query-50.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
.. class:: copyable-code
77
.. code-block:: javascript
88
9-
db.inventory.find( { status: "A" }, { name: 1, status: 1, instock: { $slice: -1 } } )
9+
db.inventory.find( { status: "A" }, { item: 1, status: 1, instock: { $slice: -1 } } )
1010
1111
- id: python
1212
content: |

source/includes/driver-example-query-intro.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
``inventory`` collection. To populate the ``inventory``
1010
collection, run the following:
1111

12+
- id: compass
13+
content: |
14+
This page provides examples of |query_operations| in
15+
:ref:`MongoDB Compass <compass-index>`. The examples on this
16+
page use the ``inventory`` collection. Populate the
17+
``inventory`` collection with the following documents:
18+
1219
- id: python
1320
content: |
1421
This page provides examples of |query_operations| using the
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
For fields that contain arrays, MongoDB provides the following
2+
projection operators for manipulating arrays: :projection:`$elemMatch`,
3+
:projection:`$slice`, and :projection:`$`.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The following example uses the :projection:`$slice` projection operator
2+
to return the last element in the ``instock`` array:

source/tutorial/project-fields-from-query-results.txt

Lines changed: 89 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Return All Fields in Matching Documents
7979
- id: scala
8080
content: |
8181
If you do not specify a :term:`projection`, the
82-
:scala-api:`collection.find()<find[C](filter:org.mongodb.scala.bson.conversions.Bson)(implicite:org.mongodb.scala.bson.DefaultHelper.DefaultsTo[C,TResult],implicitct:scala.reflect.ClassTag[C]):org.mongodb.scala.FindObservable[C]>`
82+
:scala-api:`collection.find()<find[C](filter:org.mongodb.scala.bson.conversions.Bson)(implicite:org.mongodb.scala.bson.DefaultHelper.DefaultsTo[C,TResult],implicitct:scala.reflect.ClassTag[C]):org.mongodb.scala.FindObservable[C]>`
8383
method returns all fields in the matching documents.
8484

8585
- id: csharp
@@ -141,8 +141,10 @@ fields in the matching documents:
141141

142142
.. include:: /includes/driver-example-query-46.rst
143143

144-
With the exception of the ``_id`` field, you cannot combine inclusion
145-
and exclusion statements in projection documents.
144+
.. note::
145+
146+
With the exception of the ``_id`` field, you cannot combine inclusion
147+
and exclusion statements in projection documents.
146148

147149
Return Specific Fields in Embedded Documents
148150
--------------------------------------------
@@ -151,9 +153,14 @@ You can return specific fields in an embedded document. Use the
151153
:ref:`dot notation <document-dot-notation>` to refer to the embedded
152154
field and set to ``1`` in the projection document.
153155

154-
The following example returns: the ``_id`` field (returned by default),
155-
``item`` field, ``status`` field, and the ``uom`` field in the ``size``
156-
document; the ``uom`` field remains embedded in the ``size`` document.
156+
The following example returns:
157+
158+
- The ``_id`` field (returned by default),
159+
- The ``item`` field,
160+
- The ``status`` field,
161+
- The ``uom`` field in the ``size`` document.
162+
163+
The ``uom`` field remains embedded in the ``size`` document.
157164

158165
.. include:: /includes/driver-example-query-47.rst
159166

@@ -176,39 +183,53 @@ Projection on Embedded Documents in an Array
176183
Use :ref:`dot notation <document-dot-notation>` to project specific
177184
fields inside documents embedded in an array.
178185

179-
The following example specifies a projection to return the ``item``
180-
field, the ``status`` field, and the ``qty`` field in the documents
181-
embedded in the ``instock`` array. The ``_id`` field is returned by
182-
default.
186+
The following example specifies a projection to return:
187+
188+
- The ``_id`` field (returned by default),
189+
- The ``item`` field,
190+
- The ``status`` field,
191+
- The ``qty`` field in the documents embedded in the ``instock`` array.
183192

184193
.. include:: /includes/driver-example-query-49.rst
185194

186195
Project Specific Array Elements in the Returned Array
187196
-----------------------------------------------------
188197

189-
For fields that contain arrays, MongoDB provides the following
190-
projection operators: :projection:`$elemMatch`, :projection:`$slice`,
191-
and :projection:`$`.
192-
193-
The following example uses the :projection:`$slice` projection operator
194-
to return just the last element in the ``instock`` array.
195-
196-
.. include:: /includes/driver-example-query-50.rst
197-
198198
.. tabs-drivers::
199199

200200
tabs:
201201
- id: shell
202202
content: |
203+
.. include:: /includes/fact-projection-ops.rst
204+
205+
.. include:: /includes/fact-projection-slice-example.rst
206+
207+
.. include:: /includes/driver-example-query-50.rst
208+
203209
:projection:`$elemMatch`, :projection:`$slice`, and
204210
:projection:`$` are the *only* way to project specific elements
205211
to include in the returned array. For instance, you *cannot*
206212
project specific array elements using the array index; e.g.
207213
``{ "instock.0": 1 }`` projection will *not* project the array
208214
with the first element.
209215

216+
- id: compass
217+
content: |
218+
Currently, MongoDB Compass does not support any methods for
219+
projecting specific array elements in a returned array.
220+
221+
For additional details and examples on projection in MongoDB
222+
Compass, refer to the Compass
223+
:ref:`Query Bar <query-bar-project>` documentation.
224+
210225
- id: python
211226
content: |
227+
.. include:: /includes/fact-projection-ops.rst
228+
229+
.. include:: /includes/fact-projection-slice-example.rst
230+
231+
.. include:: /includes/driver-example-query-50.rst
232+
212233
:projection:`$elemMatch`, :projection:`$slice`, and
213234
:projection:`$` are the *only* way to project specific elements
214235
to include in the returned array. For instance, you *cannot*
@@ -218,6 +239,12 @@ to return just the last element in the ``instock`` array.
218239

219240
- id: java-sync
220241
content: |
242+
.. include:: /includes/fact-projection-ops.rst
243+
244+
.. include:: /includes/fact-projection-slice-example.rst
245+
246+
.. include:: /includes/driver-example-query-50.rst
247+
221248
:projection:`$elemMatch`, :projection:`$slice`, and
222249
:projection:`$` are the *only* way to project specific elements
223250
to include in the returned array. For instance, you *cannot*
@@ -227,6 +254,12 @@ to return just the last element in the ``instock`` array.
227254

228255
- id: java-async
229256
content: |
257+
.. include:: /includes/fact-projection-ops.rst
258+
259+
.. include:: /includes/fact-projection-slice-example.rst
260+
261+
.. include:: /includes/driver-example-query-50.rst
262+
230263
:projection:`$elemMatch`, :projection:`$slice`, and
231264
:projection:`$` are the *only* way to project specific elements
232265
to include in the returned array. For instance, you *cannot*
@@ -236,6 +269,12 @@ to return just the last element in the ``instock`` array.
236269

237270
- id: nodejs
238271
content: |
272+
.. include:: /includes/fact-projection-ops.rst
273+
274+
.. include:: /includes/fact-projection-slice-example.rst
275+
276+
.. include:: /includes/driver-example-query-50.rst
277+
239278
:projection:`$elemMatch`, :projection:`$slice`, and
240279
:projection:`$` are the *only* way to project specific elements
241280
to include in the returned array. For instance, you *cannot*
@@ -245,6 +284,12 @@ to return just the last element in the ``instock`` array.
245284

246285
- id: php
247286
content: |
287+
.. include:: /includes/fact-projection-ops.rst
288+
289+
.. include:: /includes/fact-projection-slice-example.rst
290+
291+
.. include:: /includes/driver-example-query-50.rst
292+
248293
:projection:`$elemMatch`, :projection:`$slice`, and
249294
:projection:`$` are the *only* way to project specific elements
250295
to include in the returned array. For instance, you *cannot*
@@ -254,6 +299,12 @@ to return just the last element in the ``instock`` array.
254299

255300
- id: perl
256301
content: |
302+
.. include:: /includes/fact-projection-ops.rst
303+
304+
.. include:: /includes/fact-projection-slice-example.rst
305+
306+
.. include:: /includes/driver-example-query-50.rst
307+
257308
:projection:`$elemMatch`, :projection:`$slice`, and
258309
:projection:`$` are the *only* way to project specific elements
259310
to include in the returned array. For instance, you *cannot*
@@ -263,6 +314,12 @@ to return just the last element in the ``instock`` array.
263314

264315
- id: ruby
265316
content: |
317+
.. include:: /includes/fact-projection-ops.rst
318+
319+
.. include:: /includes/fact-projection-slice-example.rst
320+
321+
.. include:: /includes/driver-example-query-50.rst
322+
266323
:projection:`$elemMatch`, :projection:`$slice`, and
267324
:projection:`$` are the *only* way to project specific elements
268325
to include in the returned array. For instance, you *cannot*
@@ -272,6 +329,12 @@ to return just the last element in the ``instock`` array.
272329

273330
- id: scala
274331
content: |
332+
.. include:: /includes/fact-projection-ops.rst
333+
334+
.. include:: /includes/fact-projection-slice-example.rst
335+
336+
.. include:: /includes/driver-example-query-50.rst
337+
275338
:projection:`$elemMatch`, :projection:`$slice`, and
276339
:projection:`$` are the *only* way to project specific elements
277340
to include in the returned array. For instance, you *cannot*
@@ -281,6 +344,12 @@ to return just the last element in the ``instock`` array.
281344

282345
- id: csharp
283346
content: |
347+
.. include:: /includes/fact-projection-ops.rst
348+
349+
.. include:: /includes/fact-projection-slice-example.rst
350+
351+
.. include:: /includes/driver-example-query-50.rst
352+
284353
:projection:`$elemMatch`, :projection:`$slice`, and
285354
:projection:`$` are the *only* way to project specific elements
286355
to include in the returned array.
@@ -300,3 +369,4 @@ to return just the last element in the ``instock`` array.
300369
- id: shell
301370
content: |
302371
.. include:: /includes/footnote-set-shell-batch-size.rst
372+

0 commit comments

Comments
 (0)