Skip to content

DOCS-338: Clarification that elemMatch projection only returns first match found (per SERVER-2238) #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/reference/operator/elemMatch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $elemMatch (query)
returns all documents in ``collection`` where the array ``array``
satisfies all of the conditions in the :operator:`$elemMatch`
expression, or where the value of ``value1`` is 1 and the value of
``value2`` is greater than 1. Matching arrays must have one element
``value2`` is greater than 1. Matching arrays must have at least one element
that matches all specified criteria. Therefore, the following
document would not match the above query:

Expand Down
13 changes: 8 additions & 5 deletions source/reference/projection/elemMatch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $elemMatch (projection)

{
_id: ObjectId(),
zipcode: 63109
zipcode: 63109,
dependents: [
{ name: "john", school: 102, age: 10 },
{ name: "jess", school: 102, age: 11 },
Expand All @@ -41,15 +41,18 @@ $elemMatch (projection)

The query would return all documents where the value of the
``zipcode`` field is ``63109``, while the projection excludes
the ``_id`` field and only includes those elements of the
``dependents`` array where the ``school`` element has a valueof
the ``_id`` field and only includes the first matching element of
the ``dependents`` array where the ``school`` element has a value of
``102``. The documents would take the following form:

.. code-block:: javascript

{
dependents: [
{ name: "john", school: 102, age: 10 },
{ name: "jess", school: 102, age: 11 }
{ name: "john", school: 102, age: 10 }
]
}

.. note::

The $elemMatch projection will only match one array element per source document.
2 changes: 1 addition & 1 deletion source/release-notes/2.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ New ``$elemMatch`` Projection Operator

The :projection:`$elemMatch` operator allows applications to narrow
the data returned from queries so that the query operation will only
return matching portions of an array. See the
return the first matching element in an array. See the
:doc:`/reference/projection/elemMatch` documentation and the
:issue:`SERVER-2238` and :issue:`SERVER-828` issues for more
information.
Expand Down