@@ -29,7 +29,7 @@ Sample Data
2929
3030The examples in this guide use the ``restaurants`` collection in the ``sample_restaurants``
3131database from the :atlas:`Atlas sample datasets </sample-data>`. To access this collection
32- from your {+language+} application, create a ``Mongo::Client`` that connects to an Atlas cluster
32+ from your {+language+} application, create a ``Mongo::Client`` object that connects to an Atlas cluster
3333and assign the following values to your ``database`` and ``collection`` variables:
3434
3535.. literalinclude:: /includes/write/update.rb
@@ -46,8 +46,8 @@ Update Operations
4646
4747You can update documents in MongoDB by using the following methods:
4848
49- - ``update_one``, which updates *the first document* that matches the search criteria
50- - ``update_many``, which updates *all documents* that match the search criteria
49+ - ``update_one``: Updates *the first document* that matches the search criteria
50+ - ``update_many``: Updates *all documents* that match the search criteria
5151
5252Each update method requires the following parameters:
5353
@@ -64,10 +64,9 @@ Each update method requires the following parameters:
6464Update One Document Example
6565~~~~~~~~~~~~~~~~~~~~~~~~~~~
6666
67- The following example uses the ``update_one`` method to update the
68- ``name`` field value of a document from ``"Happy Garden"`` to ``"Mountain
69- House"``. The update document uses the ``$set`` operation to update the ``name`` field
70- value:
67+ The following example uses the ``update_one`` method to find the first document
68+ where the value of the ``name`` field is ``"Happy Garden"``. It then uses the ``$set``
69+ operator to update the ``name`` field value to ``"Mountain House"``.
7170
7271.. io-code-block::
7372 :copyable: true
@@ -88,8 +87,8 @@ Update Many Documents Example
8887~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8988
9089The following example uses the ``update_many`` method to update all documents
91- in which the ``name`` field value is ``"Starbucks"``. The update document uses the
92- ``rename() `` method to change the name of the ``address`` field to ``location``:
90+ where the value of the ``name`` field is ``"Starbucks"``. The update document uses the
91+ ``$ rename`` operator to change the name of the ``address`` field to ``location``.
9392
9493.. io-code-block::
9594 :copyable: true
@@ -111,9 +110,9 @@ Customize the Update Operation
111110
112111The ``update_one`` and ``update_many`` methods accept options to configure the update
113112operation. You can pass these options individually as parameters, or you can create a
114- ``Hash`` object that contains the options and pass it as a parameter.
115- If you don't specify any options, the driver performs update
116- operations with default settings.
113+ ``Hash`` object that contains the options and pass the object as a parameter.
114+ If you don't specify any options, the driver performs the update
115+ operation with default settings.
117116
118117The following table describes the options that you can use to
119118configure the update operation:
@@ -126,36 +125,36 @@ configure the update operation:
126125 - Description
127126
128127 * - ``upsert``
129- - | Specifies whether the update operation performs an upsert operation if no
128+ - | Whether the update operation performs an upsert operation if no
130129 documents match the query filter. For more information, see the :manual:`upsert
131130 statement </reference/command/update/#std-label-update-command-upsert>`
132131 in the {+mdb-server+} manual.
133- | Defaults to ``false``
132+ | Default: ``false``
134133
135134 * - ``bypass_document_validation``
136- - | Specifies whether the update operation bypasses document validation. This lets you
135+ - | Whether the update operation bypasses document validation. This lets you
137136 update documents that don't meet the schema validation requirements, if any
138137 exist. For more information about schema validation, see :manual:`Schema
139138 Validation </core/schema-validation/#schema-validation>` in the MongoDB
140139 Server manual.
141- | Defaults to ``false``.
140+ | Default: ``false``
142141
143142 * - ``collation``
144- - | Specifies the kind of language collation to use when sorting
143+ - | The kind of language collation to use when sorting
145144 results. For more information, see :manual:`Collation </reference/collation/#std-label-collation>`
146145 in the {+mdb-server+} manual.
147146
148147 * - ``array_filters``
149- - | Provides a list of filters that you specify to select which
148+ - | List of filters that you specify to select which
150149 array elements the update applies to.
151150
152151 * - ``hint``
153- - | Sets the index to use when matching documents.
152+ - | Index to use when matching documents.
154153 For more information, see the :manual:`hint statement </reference/command/update/#std-label-update-command-hint>`
155154 in the {+mdb-server+} manual.
156155
157156 * - ``let``
158- - | Provides a map of parameter names and values to set top-level
157+ - | A map of parameter names and values to set top-level
159158 variables for the operation. Values must be constant or closed
160159 expressions that don't reference document fields. For more information,
161160 see the :manual:`let statement
@@ -165,15 +164,14 @@ configure the update operation:
165164Modify Update Example
166165`````````````````````
167166
168- This example creates and passes options to the ``update_one`` method.
169- The example uses the ``$equal`` operation to match documents
170- in which the ``name`` field value is ``"Sunrise Pizzeria"``. It then uses the ``$set``
171- operation to set the ``borough`` field value in the first matching document to
167+ The example uses the ``$equal`` operator to match documents
168+ where the value of the ``name`` field is ``"Sunrise Pizzeria"``. It then uses the ``$set``
169+ operator to set the ``borough`` field value in the first matching document to
172170``"Queens"`` and the ``cuisine`` field value to ``"Italian"``.
173171
174- Because the ``upsert`` option is set to ``true``, the driver inserts a new document that
175- has the fields and values specified in the filter and update document if the query filter
176- doesn't match any existing documents.
172+ Because the ``upsert`` option is set to ``true``, if the query filter
173+ doesn't match any existing documents, the driver inserts a new document that
174+ has the fields and values in the filter and update documents.
177175
178176.. io-code-block::
179177 :copyable: true
@@ -194,7 +192,7 @@ Return Value
194192~~~~~~~~~~~~
195193
196194The ``update_one`` and ``update_many`` methods each return a ``Result``
197- object. You can use the access the following instance methods from a ``Result`` instance:
195+ object. You can access the following methods from a ``Result`` instance:
198196
199197.. list-table::
200198 :widths: 30 70
@@ -204,11 +202,11 @@ object. You can use the access the following instance methods from a ``Result``
204202 - Description
205203
206204 * - ``matched_count``
207- - | Returns the number of documents that matched the query filter, regardless of
205+ - | Number of documents that matched the query filter, regardless of
208206 how many updates were performed.
209207
210208 * - ``modified_count``
211- - | Returns the number of documents modified by the update operation. If an updated
209+ - | Number of documents modified by the update operation. If an updated
212210 document is identical to the original, it is not included in this
213211 count.
214212
@@ -223,12 +221,13 @@ object. You can use the access the following instance methods from a ``Result``
223221 - | Returns the ``_id`` value of the document that was upserted
224222 in the database, if the driver performed an upsert.
225223
226- .. note ::
224+ .. tip ::
227225
228- If the ``acknowledged?`` method returns ``false``, trying to
229- access other information from the ``Result`` instance results in an
230- ``InvalidOperation`` exception. The driver cannot
231- determine these values if the server does not acknowledge the write
226+ Check the value of the ``acknowledged?`` method before you try
227+ to call any other ``Result`` methods. If the ``acknowledged?``
228+ method returns ``false``, the driver throws an ``InvalidOperation``
229+ exception if you try to call any other method on the ``Result`` object.
230+ The driver cannot determine these values if the server does not acknowledge the write
232231 operation.
233232
234233Additional Information
0 commit comments