Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 46 additions & 18 deletions source/data-formats/bson.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ The following example reads the sample BSON document from ``file.bson``:
.. input::
:language: python

with open("file.bson", "rb") as file:
data = file.read()
document = bson.decode(data)
print(document)
with open("file.bson", "rb") as file:
data = file.read()
document = bson.decode(data)
print(document)

.. output::
:visible: false
Expand Down Expand Up @@ -138,25 +138,53 @@ constructor to ``RawBSONDocument``.
first convert it to a {+language+} dictionary.

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

.. io-code-block::
:copyable: true
.. tabs::

.. tab:: Synchronous
:tabid: sync

.. input::
:language: python

from bson.raw_bson import RawBSONDocument
.. io-code-block::
:copyable: true

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

.. output::
:visible: false
client = pymongo.MongoClient("<connection URI>", document_class=RawBSONDocument)
collection = client.sample_restaurants.restaurants
raw_doc = collection.find_one({"name": "Mongo's Pizza"})
print(type(raw_doc))

.. output::
:visible: false

<class 'bson.raw_bson.RawBSONDocument'>

.. tab:: Asynchronous
:tabid: async

.. io-code-block::
:copyable: true

.. input::
:language: python

from bson.raw_bson import RawBSONDocument

client = pymongo.AsyncMongoClient("<connection URI>", document_class=RawBSONDocument)
collection = client.sample_restaurants.restaurants
raw_doc = await collection.find_one({"name": "Mongo's Pizza"})
print(type(raw_doc))

.. output::
:visible: false

<class 'bson.raw_bson.RawBSONDocument'>
<class 'bson.raw_bson.RawBSONDocument'>

API Documentation
-----------------
Expand Down
Loading
Loading