Skip to content

Commit fa00685

Browse files
committed
DOCSP-48120: elemmatch method overload
1 parent 9d38c02 commit fa00685

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

source/fundamentals/builders.txt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ to a LINQ query:
9999
var filter = builder.Lt("Price", 20) & builder.Eq("Category", "Perennial");
100100
var query = collection.AsQueryable().Where(f => filter.Inject());
101101

102+
.. _csharp-builders-array-operators:
103+
102104
Array Operators
103105
~~~~~~~~~~~~~~~
104106

@@ -126,6 +128,24 @@ criteria. The following example returns documents that contain the value
126128
var builder = Builders<Flower>.Filter;
127129
var filter = builder.ElemMatch(f => f.Season, s => s == "Summer");
128130

131+
.. tip:: ElemMatch() Overload
132+
133+
The ``ElemMatch()`` method has an overload to accept a single filter
134+
parameter. This functionality supports performing queries that
135+
include nested ``$elemMatch`` statements.
136+
137+
The following code demonstrates how to construct a nested
138+
``$elemMatch`` query that uses both implementations of the
139+
``ElemMatch()`` method:
140+
141+
.. code-block:: csharp
142+
143+
// ElemMatch() with only filter parameter
144+
var arrayFilter = Builders<MyEntry[]>.Filter.ElemMatch(<filter>);
145+
146+
// ElemMatch() with field name and filter parameters
147+
var filter = Builders<MyClass>.Filter.ElemMatch(<array field name>, arrayFilter);
148+
129149
To learn more about array operators, see the :manual:`Array Query Operators
130150
</reference/operator/query-array/>` guide in the {+mdb-server+} manual.
131151

@@ -491,4 +511,5 @@ guide, see the following API Documentation:
491511
- `SortDefinitionBuilder <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.SortDefinitionBuilder-1.html>`__
492512
- `UpdateDefinitionBuilder <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.UpdateDefinitionBuilder-1.html>`__
493513
- `IndexKeysDefinitionBuilder <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IndexKeysDefinitionBuilder-1.html>`__
494-
- `PipelineDefinitionBuilder <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.PipelineDefinitionBuilder.html>`__
514+
- `PipelineDefinitionBuilder
515+
<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.PipelineDefinitionBuilder.html>`__

source/whats-new.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ The 3.3 driver release includes the following new features:
4646
``create`` events in the ``ChangeStreamDocument`` class. To learn more
4747
about change streams, see the :ref:`csharp-change-streams` guide.
4848

49+
- Supports nested ``$elemMatch`` queries by providing an overload of the
50+
``ElemMatch()`` method that takes only a filter parameter. To learn
51+
more, see the :ref:`csharp-builders-array-operators` section of the
52+
Builders guide.
53+
4954
.. _csharp-version-3.2:
5055

5156
What's New in 3.2
@@ -426,4 +431,5 @@ The 2.22 driver release includes the following new features:
426431
- Reduced memory allocation when using encryption.
427432
- Added logging messages for server discovery and monitoring (SDAM) events. For more
428433
information on these events, see the
429-
`MongoDB SDAM Logging and Monitoring specification. <https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring-logging-and-monitoring.rst#log-messages>`__
434+
`MongoDB SDAM Logging and Monitoring specification.
435+
<https://github.com/mongodb/specifications/blob/master/source/server-discovery-and-monitoring/server-discovery-and-monitoring-logging-and-monitoring.rst#log-messages>`__

0 commit comments

Comments
 (0)