From cfdd2c1c726b2518c86db6a35ebf5cb58c9f5a3e Mon Sep 17 00:00:00 2001 From: rustagir Date: Tue, 8 Apr 2025 14:56:29 -0400 Subject: [PATCH 1/2] DOCSP-45429: sort for update and replace one --- .../crud/write-operations/replace.txt | 18 +++++++++++++++++- .../includes/page-templates/update/update.rst | 17 ++++++++++++++++- source/whats-new.txt | 8 +++++--- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/source/fundamentals/crud/write-operations/replace.txt b/source/fundamentals/crud/write-operations/replace.txt index 34ef27e0..1d91b40d 100644 --- a/source/fundamentals/crud/write-operations/replace.txt +++ b/source/fundamentals/crud/write-operations/replace.txt @@ -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 + performs the replace operation. To set this option, you must + instantiate a ``ReplaceOptions`` instance that uses a generic + type that models your data, as shown in the following code: + + .. code-block:: csharp + + var options = new ReplaceOptions + { + Sort = Builders.Sort.Ascending(r => r.Name) + }; + + **Data Type:** ``SortDefinition`` + * - ``Let`` - Gets or sets the let document. See :manual:`the {+mdb-server+} manual ` @@ -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>`__ \ No newline at end of file +* `ReplaceOneResult + <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.ReplaceOneResult.html>`__ diff --git a/source/includes/page-templates/update/update.rst b/source/includes/page-templates/update/update.rst index 49741885..4815e74f 100644 --- a/source/includes/page-templates/update/update.rst +++ b/source/includes/page-templates/update/update.rst @@ -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`` instance that uses a generic + type that models your data, as shown in the following code: + + .. code-block:: csharp + + var options = new UpdateOptions + { + Sort = Builders.Sort.Ascending(r => r.Name) + }; + + **Data Type:** ``SortDefinition`` + * - ``Let`` - Gets or sets the let document. See :manual:`the {+mdb-server+} manual ` @@ -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| \ No newline at end of file +|instruqt-lab-component| diff --git a/source/whats-new.txt b/source/whats-new.txt index 4ac55477..915a59fb 100644 --- a/source/whats-new.txt +++ b/source/whats-new.txt @@ -149,9 +149,11 @@ The 3.1 driver release includes the following new features: Vector Search, see :atlas:`Run Vector Search Queries ` 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 `. From 7bd924ec9519aadfc0f007900983b187bbb7a312 Mon Sep 17 00:00:00 2001 From: rustagir Date: Tue, 15 Apr 2025 11:04:49 -0400 Subject: [PATCH 2/2] FP tech review 1 --- source/fundamentals/crud/write-operations/replace.txt | 10 ++++++---- source/includes/page-templates/update/update.rst | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/source/fundamentals/crud/write-operations/replace.txt b/source/fundamentals/crud/write-operations/replace.txt index 1d91b40d..856512fc 100644 --- a/source/fundamentals/crud/write-operations/replace.txt +++ b/source/fundamentals/crud/write-operations/replace.txt @@ -184,10 +184,12 @@ The ``ReplaceOptions`` class contains the following properties: **Data Type:** ``bool`` * - ``Sort`` - - Specifies a sort order to apply to documents before the server - performs the replace operation. To set this option, you must - instantiate a ``ReplaceOptions`` instance that uses a generic - type that models your data, as shown in the following code: + - Determines which document the operation replaces if the query + selects multiple documents, because the replace operation replaces + the first document in the sort order specified. To set this + option, you must instantiate an ``ReplaceOptions`` instance + that uses a generic type that models your data, as shown in the + following code: .. code-block:: csharp diff --git a/source/includes/page-templates/update/update.rst b/source/includes/page-templates/update/update.rst index 4815e74f..75401284 100644 --- a/source/includes/page-templates/update/update.rst +++ b/source/includes/page-templates/update/update.rst @@ -193,10 +193,12 @@ 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`` instance that uses a generic - type that models your data, as shown in the following code: + - Determines which document the operation updates if the query + selects multiple documents, because the update operation updates + the first document in the sort order specified. To set this + option, you must instantiate an ``UpdateOptions`` instance + that uses a generic type that models your data, as shown in the + following code: .. code-block:: csharp