Skip to content

Commit ab4b275

Browse files
committed
replace instructions
1 parent c37610e commit ab4b275

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

source/usage-examples/replace.txt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,22 @@ Example
2626
-------
2727

2828
This example replaces a document in the ``restaurants`` collection of
29-
the ``sample_restaurants`` database. The example uses a ``Restaurant``
30-
struct that has ``name``, ``borough``, and ``cuisine`` fields to model
31-
documents in the collection.
29+
the ``sample_restaurants`` database. The ``replace_one()`` method replaces
30+
the first document in which the value of the ``name`` field is
31+
``"Landmark Coffee Shop"`` with a new document.
3232

33-
The following code replaces a document in which the value of the
34-
``name`` field is ``"Landmark Coffee Shop"`` with a new document. MongoDB
35-
replaces the first document that matches the query filter.
33+
You can access the documents in the ``restaurants`` collection as instances
34+
of the BSON data type or a custom data type. To specify which data type represents
35+
the collection's data, perform the following actions on the highlighted lines:
36+
37+
- To access collection documents as BSON documents, replace the ``<T>`` type
38+
parameter with ``<Document>`` and the ``<struct or doc>`` placeholder with
39+
``replace_doc``.
40+
41+
- To access collection documents as instances of the ``Restaurant`` struct,
42+
replace the ``<T>`` type parameter with ``<Restaurant>`` and the ``<struct or doc>``
43+
placeholder with ``replace_struct``. The ``Restaurant`` struct is defined at
44+
the top of the code file.
3645

3746
Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to
3847
see the corresponding code for each runtime:
@@ -47,6 +56,7 @@ see the corresponding code for each runtime:
4756

4857
.. input:: /includes/usage-examples/code-snippets/replace-async.rs
4958
:language: rust
59+
:emphasize-lines: 19, 36
5060
:dedent:
5161

5262
.. output::
@@ -63,6 +73,7 @@ see the corresponding code for each runtime:
6373

6474
.. input:: /includes/usage-examples/code-snippets/replace-sync.rs
6575
:language: rust
76+
:emphasize-lines: 18, 35
6677
:dedent:
6778

6879
.. output::

0 commit comments

Comments
 (0)