Skip to content

Commit ca969d4

Browse files
authored
DOCSP-48120: elemmatch method overload (#537)
* merge upstream * small fix * MW PR fixes 1 * RStam tech review
1 parent bd69fc6 commit ca969d4

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

source/fundamentals/builders.txt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,25 @@ criteria. The following example returns documents that contain the value
128128
var builder = Builders<Flower>.Filter;
129129
var filter = builder.ElemMatch(f => f.Season, s => s == "Summer");
130130

131+
.. tip:: ElemMatch() Overload
132+
133+
The ``ElemMatch()`` method has an overload that accepts a single *filter*
134+
parameter. You can use this overload to perform ``$elemMatch``
135+
queries directly against values. This functionality can support
136+
queries that include nested ``$elemMatch`` statements.
137+
138+
The following code demonstrates how to construct a nested
139+
``$elemMatch`` query that uses multiple overloads of the
140+
``ElemMatch()`` method:
141+
142+
.. code-block:: csharp
143+
144+
// ElemMatch() with only filter parameter
145+
var arrayFilter = Builders<MyEntry[]>.Filter.ElemMatch(<filter>);
146+
147+
// ElemMatch() with field name and filter parameters
148+
var filter = Builders<MyClass>.Filter.ElemMatch(<array field name>, arrayFilter);
149+
131150
To learn more about array operators, see the :manual:`Array Query Operators
132151
</reference/operator/query-array/>` guide in the {+mdb-server+} manual.
133152

@@ -493,4 +512,5 @@ guide, see the following API Documentation:
493512
- `SortDefinitionBuilder <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.SortDefinitionBuilder-1.html>`__
494513
- `UpdateDefinitionBuilder <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.UpdateDefinitionBuilder-1.html>`__
495514
- `IndexKeysDefinitionBuilder <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IndexKeysDefinitionBuilder-1.html>`__
496-
- `PipelineDefinitionBuilder <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.PipelineDefinitionBuilder.html>`__
515+
- `PipelineDefinitionBuilder
516+
<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.PipelineDefinitionBuilder.html>`__

source/whats-new.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ The 3.3 driver release includes the following new features:
7474
- Adds support for the ``$rankFusion`` aggregation stage, which enables rank-based
7575
result scoring on combined results from multiple pipelines.
7676

77-
- Adds support for nested :manual:`$elemMatch </reference/operator/query/elemMatch/>`
78-
queries by providing an overload of the ``ElemMatch()`` method that takes only a filter
79-
parameter. To learn more, see the :ref:`csharp-builders-array-operators` section of the
77+
- Adds support for :manual:`$elemMatch </reference/operator/query/elemMatch/>`
78+
queries directly against values by providing an overload of the
79+
``ElemMatch()`` method that takes only a filter parameter. To learn
80+
more, see the :ref:`csharp-builders-array-operators` section of the
8081
Builders guide.
8182

8283
- Adds support for using the ``OfType<T>()`` method and ``is`` operator to check
@@ -400,4 +401,4 @@ The 2.25 driver release includes the following new features:
400401
- Added support for overriding the ``"mongodb"`` service name with a custom one
401402
by using the ``srvServiceName`` connection option.
402403
- Improved behavior of bulk write operations to prevent enumerating the requests
403-
parameter more than once.
404+
parameter more than once.

0 commit comments

Comments
 (0)