File tree Expand file tree Collapse file tree 3 files changed +10
-7
lines changed Expand file tree Collapse file tree 3 files changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ $elemMatch (query)
20
20
returns all documents in ``collection`` where the array ``array``
21
21
satisfies all of the conditions in the :operator:`$elemMatch`
22
22
expression, or where the value of ``value1`` is 1 and the value of
23
- ``value2`` is greater than 1. Matching arrays must have one element
23
+ ``value2`` is greater than 1. Matching arrays must have at least one element
24
24
that matches all specified criteria. Therefore, the following
25
25
document would not match the above query:
26
26
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ $elemMatch (projection)
22
22
23
23
{
24
24
_id: ObjectId(),
25
- zipcode: 63109
25
+ zipcode: 63109,
26
26
dependents: [
27
27
{ name: "john", school: 102, age: 10 },
28
28
{ name: "jess", school: 102, age: 11 },
@@ -41,15 +41,18 @@ $elemMatch (projection)
41
41
42
42
The query would return all documents where the value of the
43
43
``zipcode`` field is ``63109``, while the projection excludes
44
- the ``_id`` field and only includes those elements of the
45
- ``dependents`` array where the ``school`` element has a valueof
44
+ the ``_id`` field and only includes the first matching element of
45
+ the ``dependents`` array where the ``school`` element has a value of
46
46
``102``. The documents would take the following form:
47
47
48
48
.. code-block:: javascript
49
49
50
50
{
51
51
dependents: [
52
- { name: "john", school: 102, age: 10 },
53
- { name: "jess", school: 102, age: 11 }
52
+ { name: "john", school: 102, age: 10 }
54
53
]
55
54
}
55
+
56
+ .. note::
57
+
58
+ The $elemMatch projection will only match one array element per source document.
Original file line number Diff line number Diff line change @@ -303,7 +303,7 @@ New ``$elemMatch`` Projection Operator
303
303
304
304
The :projection:`$elemMatch` operator allows applications to narrow
305
305
the data returned from queries so that the query operation will only
306
- return matching portions of an array. See the
306
+ return the first matching element in an array. See the
307
307
:doc:`/reference/projection/elemMatch` documentation and the
308
308
:issue:`SERVER-2238` and :issue:`SERVER-828` issues for more
309
309
information.
You can’t perform that action at this time.
0 commit comments