@@ -79,7 +79,7 @@ Return All Fields in Matching Documents
79
79
- id: scala
80
80
content: |
81
81
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]>`
83
83
method returns all fields in the matching documents.
84
84
85
85
- id: csharp
@@ -141,8 +141,10 @@ fields in the matching documents:
141
141
142
142
.. include:: /includes/driver-example-query-46.rst
143
143
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.
146
148
147
149
Return Specific Fields in Embedded Documents
148
150
--------------------------------------------
@@ -151,9 +153,14 @@ You can return specific fields in an embedded document. Use the
151
153
:ref:`dot notation <document-dot-notation>` to refer to the embedded
152
154
field and set to ``1`` in the projection document.
153
155
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.
157
164
158
165
.. include:: /includes/driver-example-query-47.rst
159
166
@@ -176,39 +183,53 @@ Projection on Embedded Documents in an Array
176
183
Use :ref:`dot notation <document-dot-notation>` to project specific
177
184
fields inside documents embedded in an array.
178
185
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.
183
192
184
193
.. include:: /includes/driver-example-query-49.rst
185
194
186
195
Project Specific Array Elements in the Returned Array
187
196
-----------------------------------------------------
188
197
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
-
198
198
.. tabs-drivers::
199
199
200
200
tabs:
201
201
- id: shell
202
202
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
+
203
209
:projection:`$elemMatch`, :projection:`$slice`, and
204
210
:projection:`$` are the *only* way to project specific elements
205
211
to include in the returned array. For instance, you *cannot*
206
212
project specific array elements using the array index; e.g.
207
213
``{ "instock.0": 1 }`` projection will *not* project the array
208
214
with the first element.
209
215
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
+
210
225
- id: python
211
226
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
+
212
233
:projection:`$elemMatch`, :projection:`$slice`, and
213
234
:projection:`$` are the *only* way to project specific elements
214
235
to include in the returned array. For instance, you *cannot*
@@ -218,6 +239,12 @@ to return just the last element in the ``instock`` array.
218
239
219
240
- id: java-sync
220
241
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
+
221
248
:projection:`$elemMatch`, :projection:`$slice`, and
222
249
:projection:`$` are the *only* way to project specific elements
223
250
to include in the returned array. For instance, you *cannot*
@@ -227,6 +254,12 @@ to return just the last element in the ``instock`` array.
227
254
228
255
- id: java-async
229
256
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
+
230
263
:projection:`$elemMatch`, :projection:`$slice`, and
231
264
:projection:`$` are the *only* way to project specific elements
232
265
to include in the returned array. For instance, you *cannot*
@@ -236,6 +269,12 @@ to return just the last element in the ``instock`` array.
236
269
237
270
- id: nodejs
238
271
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
+
239
278
:projection:`$elemMatch`, :projection:`$slice`, and
240
279
:projection:`$` are the *only* way to project specific elements
241
280
to include in the returned array. For instance, you *cannot*
@@ -245,6 +284,12 @@ to return just the last element in the ``instock`` array.
245
284
246
285
- id: php
247
286
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
+
248
293
:projection:`$elemMatch`, :projection:`$slice`, and
249
294
:projection:`$` are the *only* way to project specific elements
250
295
to include in the returned array. For instance, you *cannot*
@@ -254,6 +299,12 @@ to return just the last element in the ``instock`` array.
254
299
255
300
- id: perl
256
301
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
+
257
308
:projection:`$elemMatch`, :projection:`$slice`, and
258
309
:projection:`$` are the *only* way to project specific elements
259
310
to include in the returned array. For instance, you *cannot*
@@ -263,6 +314,12 @@ to return just the last element in the ``instock`` array.
263
314
264
315
- id: ruby
265
316
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
+
266
323
:projection:`$elemMatch`, :projection:`$slice`, and
267
324
:projection:`$` are the *only* way to project specific elements
268
325
to include in the returned array. For instance, you *cannot*
@@ -272,6 +329,12 @@ to return just the last element in the ``instock`` array.
272
329
273
330
- id: scala
274
331
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
+
275
338
:projection:`$elemMatch`, :projection:`$slice`, and
276
339
:projection:`$` are the *only* way to project specific elements
277
340
to include in the returned array. For instance, you *cannot*
@@ -281,6 +344,12 @@ to return just the last element in the ``instock`` array.
281
344
282
345
- id: csharp
283
346
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
+
284
353
:projection:`$elemMatch`, :projection:`$slice`, and
285
354
:projection:`$` are the *only* way to project specific elements
286
355
to include in the returned array.
@@ -300,3 +369,4 @@ to return just the last element in the ``instock`` array.
300
369
- id: shell
301
370
content: |
302
371
.. include:: /includes/footnote-set-shell-batch-size.rst
372
+
0 commit comments