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)
2020 returns all documents in ``collection`` where the array ``array``
2121 satisfies all of the conditions in the :operator:`$elemMatch`
2222 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
2424 that matches all specified criteria. Therefore, the following
2525 document would not match the above query:
2626
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ $elemMatch (projection)
2222
2323 {
2424 _id: ObjectId(),
25- zipcode: 63109
25+ zipcode: 63109,
2626 dependents: [
2727 { name: "john", school: 102, age: 10 },
2828 { name: "jess", school: 102, age: 11 },
@@ -41,15 +41,18 @@ $elemMatch (projection)
4141
4242 The query would return all documents where the value of the
4343 ``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
4646 ``102``. The documents would take the following form:
4747
4848 .. code-block:: javascript
4949
5050 {
5151 dependents: [
52- { name: "john", school: 102, age: 10 },
53- { name: "jess", school: 102, age: 11 }
52+ { name: "john", school: 102, age: 10 }
5453 ]
5554 }
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
303303
304304The :projection:`$elemMatch` operator allows applications to narrow
305305the 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
307307:doc:`/reference/projection/elemMatch` documentation and the
308308:issue:`SERVER-2238` and :issue:`SERVER-828` issues for more
309309information.
You can’t perform that action at this time.
0 commit comments