@@ -124,23 +124,34 @@ Work with Raw BSON Data
124
124
some situations that might require using raw BSON documents:
125
125
126
126
- Moving a document between databases or collections
127
- - Writing binary blobs to a disk
127
+ - Writing binary data to a disk
128
128
- Bypassing the performance overhead of converting to and from {+language+} dictionaries
129
129
130
- You can use the ``RawBSONDocument`` class to represent raw BSON documents. To use
131
- ``RawBSONDocument`` objects to represent documents in your collection, set the
132
- ``document_class`` parameter of the ``MongoClient`` constructor to ``RawBSONDocument``.
130
+ The ``RawBSONDocument`` class is a representation of a BSON document that provides
131
+ access to the underlying raw BSON bytes. To use ``RawBSONDocument`` objects to represent
132
+ documents in your collection, set the ``document_class`` parameter of the ``MongoClient``
133
+ constructor to ``RawBSONDocument``.
133
134
134
- The following example configures a ``MongoClient`` object to use ``RawBSONDocument``,
135
- then retrieves the sample document:
135
+ The following example configures a ``MongoClient`` object to use ``RawBSONDocument`` objects
136
+ to model the collection, then retrieves the sample document from the preceding examples :
136
137
137
- .. code-block:: python
138
+ .. io-code-block::
139
+ :copyable: true
140
+
141
+ .. input::
142
+ :language: python
138
143
139
144
from bson.raw_bson import RawBSONDocument
140
145
141
146
client = pymongo.MongoClient("<connection URI>", document_class=RawBSONDocument)
142
- collection = client["<database name>"]["<collection name>"]
147
+ collection = client.sample_restaurants.restaurants
143
148
raw_doc = collection.find_one({"name": "Mongo's Pizza"})
149
+ print(type(raw_doc))
150
+
151
+ .. output::
152
+ :visible: false
153
+
154
+ <class 'bson.raw_bson.RawBSONDocument'>
144
155
145
156
.. note::
146
157
0 commit comments