Skip to content

Commit 764c849

Browse files
committed
DOCSP-48166: Add async examples for Data Formats pages (#213)
(cherry picked from commit 02cb636)
1 parent 09a2577 commit 764c849

File tree

4 files changed

+774
-269
lines changed

4 files changed

+774
-269
lines changed

source/data-formats/bson.txt

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ The following example reads the sample BSON document from ``file.bson``:
107107
.. input::
108108
:language: python
109109

110-
with open("file.bson", "rb") as file:
111-
data = file.read()
112-
document = bson.decode(data)
113-
print(document)
110+
with open("file.bson", "rb") as file:
111+
data = file.read()
112+
document = bson.decode(data)
113+
print(document)
114114

115115
.. output::
116116
:visible: false
@@ -140,25 +140,53 @@ constructor to ``RawBSONDocument``.
140140
first convert it to a {+language+} dictionary.
141141

142142
The following example configures a ``MongoClient`` object to use ``RawBSONDocument`` objects
143-
to model the collection, then retrieves the sample document from the preceding examples:
143+
to model the collection, then retrieves the sample document from the preceding examples.
144+
Select the :guilabel:`Synchronous` or :guilabel:`Asynchronous` tab to see the corresponding
145+
code.
144146

145-
.. io-code-block::
146-
:copyable: true
147+
.. tabs::
148+
149+
.. tab:: Synchronous
150+
:tabid: sync
147151

148-
.. input::
149-
:language: python
150-
151-
from bson.raw_bson import RawBSONDocument
152+
.. io-code-block::
153+
:copyable: true
152154

153-
client = pymongo.MongoClient("<connection URI>", document_class=RawBSONDocument)
154-
collection = client.sample_restaurants.restaurants
155-
raw_doc = collection.find_one({"name": "Mongo's Pizza"})
156-
print(type(raw_doc))
155+
.. input::
156+
:language: python
157+
158+
from bson.raw_bson import RawBSONDocument
157159

158-
.. output::
159-
:visible: false
160+
client = pymongo.MongoClient("<connection URI>", document_class=RawBSONDocument)
161+
collection = client.sample_restaurants.restaurants
162+
raw_doc = collection.find_one({"name": "Mongo's Pizza"})
163+
print(type(raw_doc))
164+
165+
.. output::
166+
:visible: false
167+
168+
<class 'bson.raw_bson.RawBSONDocument'>
169+
170+
.. tab:: Asynchronous
171+
:tabid: async
172+
173+
.. io-code-block::
174+
:copyable: true
175+
176+
.. input::
177+
:language: python
178+
179+
from bson.raw_bson import RawBSONDocument
180+
181+
client = pymongo.AsyncMongoClient("<connection URI>", document_class=RawBSONDocument)
182+
collection = client.sample_restaurants.restaurants
183+
raw_doc = await collection.find_one({"name": "Mongo's Pizza"})
184+
print(type(raw_doc))
185+
186+
.. output::
187+
:visible: false
160188

161-
<class 'bson.raw_bson.RawBSONDocument'>
189+
<class 'bson.raw_bson.RawBSONDocument'>
162190

163191
API Documentation
164192
-----------------

0 commit comments

Comments
 (0)