@@ -64,6 +64,8 @@ The {+driver-short+} provides the following methods to change documents:
6464You can retrieve and modify data in one action by using compound
6565operations. To learn more, see the guide on :ref:`rust-compound-operations`.
6666
67+ .. _rust-id:
68+
6769The _id Field
6870~~~~~~~~~~~~~
6971
@@ -165,22 +167,22 @@ The following documents describe employees of a company:
165167 :copyable: false
166168
167169 {
168- "_id": { ... } ,
170+ "_id": ObjectId('4337') ,
169171 "name": "Shelley Olson",
170172 "department": "Marketing",
171173 "role": "Director",
172174 "bonus": 3000
173175 },
174176 {
175- "_id": { ... } ,
177+ "_id": ObjectId('4902') ,
176178 "name": "Remi Ibrahim",
177179 "department": "Marketing",
178180 "role": "Consultant",
179181 "bonus": 1800
180182 }
181183
182- This example performs an update operation with the
183- ``update_many()`` method. The method has the following parameters:
184+ This example performs an update operation with the ``update_many()`` method.
185+ The ``update_many()`` method takes the following parameters:
184186
185187- A query filter to match documents where the value of the
186188 ``department`` field is ``"Marketing"``
@@ -204,28 +206,86 @@ This example performs an update operation with the
204206 :language: console
205207 :visible: false
206208
207- Modified 2 document(s)
209+ Modified documents: 2
208210
209- The following shows the updated documents resulting from the preceding update operation:
211+ The following documents reflect the changes resulting from the preceding update operation:
210212
211213.. code-block:: json
212214 :copyable: false
213215
214216 {
215- "_id": { ... } ,
217+ "_id": ObjectId('4337') ,
216218 "name": "Shelley Olson",
217219 "department": "Business Operations",
218220 "role": "Analytics Specialist",
219221 "bonus": 3500
220222 },
221223 {
222- "_id": { ... } ,
224+ "_id": ObjectId('4902') ,
223225 "name": "Remi Ibrahim",
224226 "department": "Business Operations",
225227 "role": "Analytics Specialist",
226228 "bonus": 2300
227229 }
228230
231+ Update by ObjectId Example
232+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
233+
234+ The following document describes an employee of a company:
235+
236+ .. code-block:: json
237+ :copyable: false
238+ :emphasize-lines: 2
239+
240+ {
241+ "_id": ObjectId('4274'),
242+ "name": "Jill Millerton",
243+ "department": "Marketing",
244+ "role": "Consultant"
245+ }
246+
247+ This example queries for the preceding document by specifying a query filter to match the
248+ document's unique ``_id`` value. Then, the code performs an update operation with the
249+ ``update_one()`` method. The ``update_one()`` method takes the following parameters:
250+
251+ - Query filter that matches a document in which the value of the ``_id`` field is
252+ ``ObjectId('4274')``
253+
254+ - Update document that creates instructions to set the value of ``name`` to
255+ ``"Jill Gillison"``
256+
257+ .. io-code-block::
258+
259+ .. input:: /includes/fundamentals/code-snippets/crud/change.rs
260+ :start-after: begin-update-by-id
261+ :end-before: end-update-by-id
262+ :language: rust
263+ :dedent:
264+
265+ .. output::
266+ :language: console
267+ :visible: false
268+
269+ Modified documents: 1
270+
271+ The following document reflects the changes resulting from the preceding update operation:
272+
273+ .. code-block:: json
274+ :copyable: false
275+
276+ {
277+ "_id": ObjectId('4274'),
278+ "name": "Jill Gillison",
279+ "department": "Marketing",
280+ "role": "Consultant"
281+ }
282+
283+ .. tip::
284+
285+ To learn more about the ``_id`` field, see the :ref:`_id Field <rust-id>`
286+ section of this page or the :manual:`ObjectId() </reference/method/ObjectId/>`
287+ method documentation in the Server manual.
288+
229289.. _rust-replace-document:
230290
231291Replace a Document
@@ -290,7 +350,7 @@ The following document describes an employee of a company:
290350 :copyable: false
291351
292352 {
293- "_id": 4501,
353+ "_id": ObjectId(' 4501') ,
294354 "name": "Matt DeGuy",
295355 "role": "Consultant",
296356 "team_members": [ "Jill Gillison", "Susan Lee" ]
@@ -315,8 +375,8 @@ the preceding document with one that has the following fields:
315375 :language: console
316376 :visible: false
317377
318- Matched 1 document(s)
319- Modified 1 document(s)
378+ Matched documents: 1
379+ Modified documents: 1
320380
321381The replaced document contains the contents of the replacement document
322382and the immutable ``_id`` field:
@@ -325,7 +385,7 @@ and the immutable ``_id`` field:
325385 :copyable: false
326386
327387 {
328- "_id": 4501,
388+ "_id": ObjectId(' 4501') ,
329389 "name": "Susan Lee",
330390 "role": "Lead Consultant",
331391 "team_members": [ "Jill Gillison" ]
0 commit comments