Skip to content

Commit 959fe5c

Browse files
committed
Merge remote-tracking branch 'upstream/master' into docsp-46362-toc-reorg
2 parents cfc6d97 + a235231 commit 959fe5c

File tree

7 files changed

+490
-171
lines changed

7 files changed

+490
-171
lines changed

snooty.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name = "pymongo"
2-
title = "PyMongo"
2+
title = "PyMongo Driver"
33
toc_landing_pages = [
44
"/get-started",
55
"/connect",

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
-----------------

source/data-formats/custom-types/serialization.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,17 @@ serialized object into a collection:
5252
self.name = name
5353
self.cuisine = cuisine
5454

55-
restaurant = Guitar("Example Cafe", "Coffee")
55+
restaurant = Restaurant("Example Cafe", "Coffee")
5656
restaurant_dict = vars(restaurant)
5757

5858
collection.insert_one(restaurant_dict)
5959

60+
The preceding example serializes the ``Restaurant`` object into the following dictionary:
61+
62+
.. code-block:: none
63+
64+
{'name': 'Example Cafe', 'cuisine': 'Coffee'}
65+
6066
To learn more about inserting documents into a collection, see the :ref:`pymongo-write-insert`
6167
guide.
6268

0 commit comments

Comments
 (0)