44Update a Document
55=================
66
7+ .. facet::
8+ :name: genre
9+ :values: reference
10+
11+ .. meta::
12+ :keywords: modify, code example
13+
14+ .. contents:: On this page
15+ :local:
16+ :backlinks: none
17+ :depth: 2
18+ :class: singlecol
19+
720You can update a document in a collection by calling the `update_one()
821<{+api+}/struct.Collection.html#method.update_one>`__ method on a
922``Collection`` instance.
@@ -26,11 +39,18 @@ Example
2639-------
2740
2841This example updates a document in the ``restaurants`` collection of
29- the ``sample_restaurants`` database.
42+ the ``sample_restaurants`` database. The ``update_one()`` method adds
43+ the ``price`` field to the first document in which the value of the ``name``
44+ field is ``"Spice Market"``.
45+
46+ You can access the documents in the ``restaurants`` collection as instances
47+ of the BSON data type or a custom data type. To specify which data type represents
48+ the collection's data, replace the ``<T>`` type parameter on the highlighted
49+ line with one of the following values:
3050
31- The following code adds the ``price`` field to a document in which the
32- value of the ``name`` field is ``"Spice Market"``. MongoDB
33- updates the first document that matches the query filter.
51+ - ``<Document>``: Accesses collection documents as BSON documents
52+ - ``<Restaurant>``: Accesses collection documents as instances of the ``Restaurant``
53+ struct, defined at the top of the code
3454
3555Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to
3656see the corresponding code for each runtime:
@@ -45,6 +65,7 @@ see the corresponding code for each runtime:
4565
4666 .. input:: /includes/usage-examples/code-snippets/update-one-async.rs
4767 :language: rust
68+ :emphasize-lines: 21
4869 :dedent:
4970
5071 .. output::
@@ -61,6 +82,7 @@ see the corresponding code for each runtime:
6182
6283 .. input:: /includes/usage-examples/code-snippets/update-one-sync.rs
6384 :language: rust
85+ :emphasize-lines: 19
6486 :dedent:
6587
6688 .. output::
0 commit comments