Skip to content

Commit 8974f96

Browse files
committed
DOCSP-45429: sort for update and replace one (#581)
* DOCSP-45429: sort for update and replace one * FP tech review 1 (cherry picked from commit f6d5c03)
1 parent e1e5903 commit 8974f96

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

source/fundamentals/crud/write-operations/replace.txt

+19-1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,23 @@ The ``ReplaceOptions`` class contains the following properties:
183183

184184
**Data Type:** ``bool``
185185

186+
* - ``Sort``
187+
- Determines which document the operation replaces if the query
188+
selects multiple documents, because the replace operation replaces
189+
the first document in the sort order specified. To set this
190+
option, you must instantiate an ``ReplaceOptions<T>`` instance
191+
that uses a generic type that models your data, as shown in the
192+
following code:
193+
194+
.. code-block:: csharp
195+
196+
var options = new ReplaceOptions<Restaurant>
197+
{
198+
Sort = Builders<Restaurant>.Sort.Ascending(r => r.Name)
199+
};
200+
201+
**Data Type:** ``SortDefinition<T>``
202+
186203
* - ``Let``
187204
- Gets or sets the let document.
188205
See :manual:`the {+mdb-server+} manual </reference/command/update/#std-label-update-let-syntax>`
@@ -268,4 +285,5 @@ see the following API documentation:
268285
* `ReplaceOne() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.ReplaceOne.html>`__
269286
* `ReplaceOneAsync() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.ReplaceOneAsync.html>`__
270287
* `ReplaceOptions <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.ReplaceOptions.html>`__
271-
* `ReplaceOneResult <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.ReplaceOneResult.html>`__
288+
* `ReplaceOneResult
289+
<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.ReplaceOneResult.html>`__

source/includes/page-templates/update/update.rst

+17
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,23 @@ The ``UpdateOptions`` class contains the following properties:
192192

193193
**Data Type:** ``bool``
194194

195+
* - ``Sort``
196+
- Determines which document the operation updates if the query
197+
selects multiple documents, because the update operation updates
198+
the first document in the sort order specified. To set this
199+
option, you must instantiate an ``UpdateOptions<T>`` instance
200+
that uses a generic type that models your data, as shown in the
201+
following code:
202+
203+
.. code-block:: csharp
204+
205+
var options = new UpdateOptions<Restaurant>
206+
{
207+
Sort = Builders<Restaurant>.Sort.Ascending(r => r.Name)
208+
};
209+
210+
**Data Type:** ``SortDefinition<T>``
211+
195212
* - ``Let``
196213
- Gets or sets the let document.
197214
See :manual:`the {+mdb-server+} manual </reference/command/update/#std-label-update-let-syntax>`

source/whats-new.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ The 3.1 driver release includes the following new features:
7070
Vector Search, see :atlas:`Run Vector Search Queries </atlas-vector-search/vector-search-stage>`
7171
in the Atlas Search documentation.
7272

73-
- Adds support for the ``sort`` option to be passed to update commands. To learn more about
74-
using update commands with the {+driver-short+}, see :ref:`csharp-update-one` and
75-
:ref:`csharp-update-many`.
73+
- Adds a sort option for update and replace operations. This change
74+
allows you to set a sort order if multiple documents match your
75+
filter when attempting to update or replace a single document. To
76+
learn more, see the :ref:`csharp-update-one` and
77+
:ref:`csharp-replace-operation` guides.
7678

7779
For more information about this release, see the :github:`v3.1 release notes
7880
</mongodb/mongo-csharp-driver/releases/tag/v3.1.0>`.

0 commit comments

Comments
 (0)