@@ -22,12 +22,16 @@ Example
2222-------
2323
2424This example retrieves a document that matches a query filter from the ``restaurants``
25- collection in the ``sample_restaurants`` database. The example populates a ``Restaurant``
26- struct with data from the retrieved document .
25+ collection in the ``sample_restaurants`` database. The ``find_one()`` method returns the
26+ first document in which the value of the ``name`` field is ``"Tompkins Square Bagels"`` .
2727
28- This example uses a query filter that matches documents in which the value of the
29- ``name`` field is ``"Tompkins Square Bagels"``. MongoDB retrieves the
30- first document that matches the query filter.
28+ You can model the retrieved document as a BSON data type or a custom data type. To specify
29+ which data type models the collection's data, replace the ``<T>`` type parameter on the
30+ highlighted line with one of the following values:
31+
32+ - ``<Document>``: Retrieves and prints collection documents as BSON documents
33+ - ``<Restaurant>``: Retrieves and prints collection documents as instances of the ``Restaurant``
34+ struct, defined at the top of the code
3135
3236Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to
3337see the corresponding code for each runtime:
@@ -37,41 +41,59 @@ see the corresponding code for each runtime:
3741 .. tab:: Asynchronous
3842 :tabid: find-one-async
3943
40- .. io-code-block::
41- :copyable: true
44+ .. literalinclude:: /includes/usage-examples/code-snippets/find-one-async.rs
45+ :language: rust
46+ :emphasize-lines: 19
47+ :dedent:
4248
43- .. input:: /includes/usage-examples/code-snippets/find-one-async.rs
44- :language: rust
45- :dedent:
49+ .. tab:: Synchronous
50+ :tabid: find-one-sync
4651
47- .. output::
48- :language: console
49- :visible: false
52+ .. literalinclude:: /includes/usage-examples/code-snippets/find-one-sync.rs
53+ :language: rust
54+ :emphasize-lines: 17
55+ :dedent:
5056
51- Some(
52- Restaurant {
53- name: "Tompkins Square Bagels",
54- cuisine: "American",
55- },
56- )
57+ Output
58+ ~~~~~~
5759
58- .. tab:: Synchronous
59- :tabid: find-one-sync
60+ Select the :guilabel:`BSON Document Result` or :guilabel:`Restaurant Struct Result` tab to
61+ see the corresponding code output based on your collection's type parameter:
6062
61- .. io-code-block::
62- :copyable: true
63+ .. tabs::
6364
64- .. input:: /includes/usage-examples/code-snippets/find-one-sync.rs
65- :language: rust
66- :dedent:
65+ .. tab:: BSON Document Result
66+ :tabid: find-one-async
67+
68+ .. code-block:: none
69+ :copyable: false
70+
71+ Some(
72+ Document({
73+ "_id": ObjectId(
74+ "...",
75+ ),
76+
77+ ...
78+
79+ "name": String(
80+ "Tompkins Square Bagels",
81+ ),
82+ "restaurant_id": String(
83+ "41605054",
84+ ),
85+ }),
86+ )
87+
88+ .. tab:: Restaurant Struct Result
89+ :tabid: find-one-sync
6790
68- .. output::
69- :language: console
70- :visible: false
91+ .. code-block:: none
92+ :copyable: false
7193
72- Some(
73- Restaurant {
74- name: "Tompkins Square Bagels",
75- cuisine: "American",
76- },
77- )
94+ Some(
95+ Restaurant {
96+ name: "Tompkins Square Bagels",
97+ cuisine: "American",
98+ },
99+ )
0 commit comments