Skip to content

Commit f1bb6f1

Browse files
committed
wip
1 parent 9b236ca commit f1bb6f1

File tree

2 files changed

+78
-42
lines changed

2 files changed

+78
-42
lines changed

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

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,33 @@ Sample Data
3333
~~~~~~~~~~~
3434

3535
The examples in this guide use the ``restaurants`` collection
36-
in the ``sample_restaurants`` database provided in the :atlas:`Atlas sample datasets </sample-data>`.
37-
To learn how to create a free MongoDB Atlas cluster and load the sample datasets,
38-
see the :ref:`<csharp-quickstart>`.
36+
from the ``sample_restaurants`` database. The documents in this
37+
collection use the following ``Restaurant``, ``Address``, and ``GradeEntry``
38+
classes as models:
39+
40+
.. literalinclude:: /includes/code-examples/Restaurant.cs
41+
:language: csharp
42+
:copyable:
43+
:dedent:
44+
45+
.. literalinclude:: /includes/code-examples/Address.cs
46+
:language: csharp
47+
:copyable:
48+
:dedent:
49+
50+
.. literalinclude:: /includes/code-examples/GradeEntry.cs
51+
:language: csharp
52+
:copyable:
53+
:dedent:
3954

4055
.. include:: /includes/convention-pack-note.rst
4156

42-
Replace Methods
43-
---------------
57+
This collection is from the :atlas:`sample datasets </sample-data>` provided
58+
by Atlas. See the :ref:`<csharp-quickstart>` to learn how to create a free MongoDB cluster
59+
and load this sample data.
60+
61+
Replace One Document
62+
--------------------
4463

4564
To replace a document in a collection, call the ``ReplaceOne()`` or ``ReplaceOneAsync()``
4665
method. These methods accept the following parameters:
@@ -53,10 +72,12 @@ method. These methods accept the following parameters:
5372
- Description
5473

5574
* - ``filter``
56-
- A *query filter* document that specifies the record to replace. You can use the
57-
``Builders`` class to create a query filter.
75+
- A *query filter* that specifies the document to replace. You can use the
76+
``Builders`` class to create a query filter.For more information about
77+
query filters, see the
78+
:manual:`{+mdb-server+} manual </core/document/#query-filter-documents>`.
5879

59-
**Data Type:** `FilterDefinition <{+new-api-root+>/MongoDB.Driver/MongoDB.Driver.FilterDefinition-1.html>`__ ``<TDocument>``
80+
**Data Type:** `FilterDefinition<TDocument> <{+new-api-root+>/MongoDB.Driver/MongoDB.Driver.FilterDefinition-1.html>`__
6081

6182
* - ``replacement``
6283
- A *replacement* document, which specifies the fields and values to insert in the new
@@ -76,7 +97,8 @@ method. These methods accept the following parameters:
7697

7798
**Data type**: `CancellationToken <https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken>`__
7899

79-
The following code example performs the following steps:
100+
The following code example demonstrates how to perform a replace operation. The
101+
code performs the following steps:
80102

81103
1. Uses the ``Builders`` class to create a query filter. The filter matches all
82104
documents where the ``cuisine`` field has the value ``"Pizza"``.

source/fundamentals/crud/write-operations/update/fields.txt

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@ Update Fields
2020
Overview
2121
--------
2222

23-
In this guide, you can learn how to use the {+driver-long+} to modify
24-
documents in a MongoDB collection by performing update operations.
23+
.. note:: Updating Arrays
2524

26-
The {+driver-short+} provides the following methods to modify documents,
27-
each of which has an asynchronous and synchronous version:
25+
This page discusses how to update document fields that contain single values.
26+
To learn how to update array values in MongoDB documents, see
27+
:ref:`<csharp-update-arrays>`.
2828

29-
- ``UpdateOneAsync()`` or ``UpdateOne()``
30-
- ``UpdateManyAsync()`` or ``UpdateMany()``
29+
In this guide, you can learn how to use the {+driver-long+} to update the
30+
values of fields in MongoDB documents.
31+
32+
The {+driver-short+} provides the following methods to update fields:
33+
34+
- ``UpdateOne()`` or ``UpdateOneAsync()``
35+
- ``UpdateMany()`` or ``UpdateManyAsync()``
3136

3237
.. tip:: Interactive Lab
3338

@@ -70,47 +75,56 @@ and load this sample data.
7075

7176
.. _csharp-update-operation:
7277

73-
Update Operations
74-
-----------------
78+
Update One Document
79+
-------------------
7580

76-
You can perform update operations in MongoDB with the following methods:
81+
To update one or more fields in a MongoDB document, call the ``UpdateOne()`` or
82+
``UpdateOneAsync()`` method. These methods accept the following parameters:
7783

78-
- ``UpdateOne()``, which updates *the first document* that matches the search criteria
79-
- ``UpdateMany()``, which updates *all documents* that match the search criteria
84+
.. list-table::
85+
:widths: 30 70
86+
:header-rows: 1
8087

81-
Required Parameters
82-
~~~~~~~~~~~~~~~~~~~
88+
* - Parameter
89+
- Description
8390

84-
Each update method requires the following parameters:
91+
* - ``filter``
92+
- A *query filter* that specifies the document to update. You can use the
93+
``Builders`` class to create a query filter. For more information about
94+
query filters, see the
95+
:manual:`{+mdb-server+} manual </core/document/#query-filter-documents>`.
8596

86-
- A **query filter** document, which determines which records to update. See the
87-
:manual:`MongoDB server manual </core/document/#query-filter-documents>` for
88-
more information about query filters.
89-
- An **update** document, which specifies the **update operator** (the kind of update to
90-
perform) and the fields and values that should change. See the
91-
:manual:`Field Update Operators Manual page</reference/operator/update-field/>` for a complete
92-
list of update operators and their usage.
97+
**Data Type:** `FilterDefinition<TDocument> <{+new-api-root+>/MongoDB.Driver/MongoDB.Driver.FilterDefinition-1.html>`__
9398

94-
The {+driver-short+} provides a ``Builders`` class that simplifies the creation of both
95-
query filters and update documents. The following code sample uses ``Builders`` to create
96-
two documents for use as parameters in an update operation:
99+
* - ``update``
100+
- An instance of the ``UpdateDefinition`` class. This object specifies the kind of update
101+
operation, the fields to update, and the new value for each field. For a complete
102+
list of update operations, see
103+
:manual:`Field Update Operators </reference/operator/update-field/>` in the
104+
{+mdb-server+} manual.
97105

98-
- A query filter that searches for restaurants with a ``cuisine`` field value of "Pizza"
99-
- An update document that sets the value of the ``cuisine`` field of these restaurants
100-
to "Pasta and breadsticks"
106+
**Data Type:** `UpdateDefinition<TDocument> <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.UpdateDefinition-1.html>`__
101107

102-
.. literalinclude:: /includes/code-examples/update-many/UpdateMany.cs
103-
:language: csharp
104-
:dedent:
105-
:start-after: // start-update-many
106-
:end-before: // end-update-many
108+
* - ``options``
109+
- *Optional.* An instance of the ``UpdateOptions`` class that specifies the
110+
configuration for the update operation. The default value is ``null``.
111+
112+
**Data Type:** `UpdateOptions <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.UpdateOptions.html>`__
113+
114+
* - ``cancellationToken``
115+
- *Optional.* A token that you can use to cancel the operation.
116+
117+
**Data type**: `CancellationToken <https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken>`__
118+
119+
The following code example demonstrates how to perform an update operation. The
120+
code performs the following steps:
107121

108122
.. tip:: Aggregation Pipelines in Update Operations
109123

110124
If you are using MongoDB Version 4.2 or later, you can use aggregation
111125
pipelines made up of a subset of aggregation stages in update operations. For
112126
more information on the aggregation stages MongoDB supports in
113-
aggregation pipelines used in update operations, see our tutorial on building
127+
aggregation pipelines used in update operations, see the tutorial about building
114128
:manual:`updates with aggregation pipelines </tutorial/update-documents-with-aggregation-pipeline/>`.
115129

116130
Update One Document

0 commit comments

Comments
 (0)