@@ -20,12 +20,15 @@ Update Fields
20
20
Overview
21
21
--------
22
22
23
- In this guide, you can learn how to use the {+driver-long+} to update the
24
- values of fields in MongoDB documents.
23
+ On this page, you can learn how to use the {+driver-long+} to update
24
+ fields in MongoDB documents. This page describes how to create ``UpdateDefinition<TDocument>``
25
+ objects that specify the update operations you want to perform on fields.
26
+ You can pass these objects to the update methods described on *this page.*
25
27
26
- The {+driver-short+} provides the following methods to update fields:
27
-
28
- - ``UpdateOne()`` or ``UpdateOneAsync()``
28
+ The {+driver-short+} supports the field update operators described in the
29
+ :manual:`{+mdb-server+} manual </reference/operator/update/#fields>`. To specify an
30
+ update operation, call the corresponding method from the ``Builders.Update`` property.
31
+ The following sections describe these methods in more detail.
29
32
30
33
.. tip:: Interactive Lab
31
34
@@ -75,16 +78,8 @@ and load this sample data.
75
78
76
79
.. _csharp-update-operation:
77
80
78
- Single Values
79
- -------------
80
-
81
- The {+driver-short+} supports the field update operators described in the
82
- :manual:`{+mdb-server+} manual </reference/operator/update/#fields>`. To specify an
83
- update operation, call the corresponding method from the ``Builders.Update`` property.
84
- The following sections describe these methods in more detail.
85
-
86
81
Increment a Value
87
- ~~~~~~~~~~~~~~~~~
82
+ -----------------
88
83
89
84
To increment the value of a field by a specific amount, call the ``Builders.Update.Inc()``
90
85
method. This method accepts the following parameters:
@@ -107,7 +102,7 @@ method. This method accepts the following parameters:
107
102
**Data Type:** ``TField``
108
103
109
104
Set If Lower or Greater
110
- ~~~~~~~~~~~~~~~~~~~~~~~
105
+ -----------------------
111
106
112
107
To update the value of the field to a specified value, *but only if the specified value
113
108
is greater than the current value of the field,* call the ``Builders.Update.Max()``
@@ -152,7 +147,7 @@ method. This method accepts the following parameters:
152
147
**Data Type:** ``TField``
153
148
154
149
Multiply a Value
155
- ~~~~~~~~~~~~~~~~
150
+ ---------------
156
151
157
152
To multiply the value of a field by a specific amount, call the ``Builders.Update.Mul()``
158
153
method. This method accepts the following parameters:
@@ -175,7 +170,7 @@ method. This method accepts the following parameters:
175
170
**Data Type:** ``TField``
176
171
177
172
Rename a Field
178
- ~~~~~~~~~~~~~~
173
+ --------------
179
174
180
175
To rename a field, call the ``Builders.Update.Rename()`` method. This method accepts the following parameters:
181
176
@@ -197,7 +192,7 @@ To rename a field, call the ``Builders.Update.Rename()`` method. This method acc
197
192
**Data Type:** ``string``
198
193
199
194
Set a Value
200
- ~~~~~~~~~~~
195
+ -----------
201
196
202
197
To set the value of a field to a specific value, call the ``Builders.Update.Set()``
203
198
method. This method accepts the following parameters:
@@ -220,7 +215,7 @@ method. This method accepts the following parameters:
220
215
**Data Type:** ``TField``
221
216
222
217
Unset a Field
223
- ~~~~~~~~~~~~~
218
+ -------------
224
219
225
220
To remove a field from a document, call the ``Builders.Update.Unset()`` method. This method accepts the following parameter:
226
221
@@ -237,7 +232,7 @@ To remove a field from a document, call the ``Builders.Update.Unset()`` method.
237
232
**Data Type:** ``Expression<Func<TDocument, TField>>``
238
233
239
234
Set on Insert
240
- ~~~~~~~~~~~~~
235
+ -------------
241
236
242
237
To set the value of a field only if the document is an upsert, call the ``Builders.Update.SetOnInsert()``
243
238
method. This method accepts the following parameters:
@@ -260,7 +255,7 @@ method. This method accepts the following parameters:
260
255
**Data Type:** ``TField``
261
256
262
257
Set the Current Date
263
- ~~~~~~~~~~~~~~~~~~~~
258
+ --------------------
264
259
265
260
To set the value of a field to the current date and time, call the ``Builders.Update.CurrentDate()``
266
261
method. This method accepts the following parameters:
0 commit comments