Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 17 additions & 1 deletion source/fundamentals/crud/write-operations/replace.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,21 @@ The ``ReplaceOptions`` class contains the following properties:

**Data Type:** ``bool``

* - ``Sort``
- Specifies a sort order to apply to documents before the server
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not totally correct because I'm not sure if the collection gets sorted before/after the match is done. We should try to be more generic, just saying that if there are multiple matches to the query, the sort order is used to decide which document will be updated/replaced. This comment is also valid for the other page.

Here it's explained as a parameter: https://www.mongodb.com/docs/manual/reference/method/db.collection.updateOne/#parameters

performs the replace operation. To set this option, you must
instantiate a ``ReplaceOptions<T>`` instance that uses a generic
type that models your data, as shown in the following code:

.. code-block:: csharp

var options = new ReplaceOptions<Restaurant>
{
Sort = Builders<Restaurant>.Sort.Ascending(r => r.Name)
};

**Data Type:** ``SortDefinition<T>``

* - ``Let``
- Gets or sets the let document.
See :manual:`the {+mdb-server+} manual </reference/command/update/#std-label-update-let-syntax>`
Expand Down Expand Up @@ -268,4 +283,5 @@ see the following API documentation:
* `ReplaceOne() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.ReplaceOne.html>`__
* `ReplaceOneAsync() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoCollection-1.ReplaceOneAsync.html>`__
* `ReplaceOptions <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.ReplaceOptions.html>`__
* `ReplaceOneResult <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.ReplaceOneResult.html>`__
* `ReplaceOneResult
<{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.ReplaceOneResult.html>`__
17 changes: 16 additions & 1 deletion source/includes/page-templates/update/update.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ The ``UpdateOptions`` class contains the following properties:

**Data Type:** ``bool``

* - ``Sort``
- Specifies a sort order to apply to documents before the server
performs the update operation. To set this option, you must
instantiate an ``UpdateOptions<T>`` instance that uses a generic
type that models your data, as shown in the following code:

.. code-block:: csharp

var options = new UpdateOptions<Restaurant>
{
Sort = Builders<Restaurant>.Sort.Ascending(r => r.Name)
};

**Data Type:** ``SortDefinition<T>``

* - ``Let``
- Gets or sets the let document.
See :manual:`the {+mdb-server+} manual </reference/command/update/#std-label-update-let-syntax>`
Expand Down Expand Up @@ -261,4 +276,4 @@ guide, see the following API documentation:
- `UpdateOptions <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.UpdateOptions.html>`__
- `UpdateResult <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.UpdateResult.html>`__

|instruqt-lab-component|
|instruqt-lab-component|
8 changes: 5 additions & 3 deletions source/whats-new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ The 3.1 driver release includes the following new features:
Vector Search, see :atlas:`Run Vector Search Queries </atlas-vector-search/vector-search-stage>`
in the Atlas Search documentation.

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

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