Skip to content

Commit ae390cc

Browse files
author
docs-builder-bot
committed
Auto-import from docs-pymongo
1 parent 1d51545 commit ae390cc

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

dbx/language-compatibility-table-pymongo.rst

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,53 @@ as binary data with subtype 0, the default subtype for binary data. In Python 3,
303303
{+driver-short+} decodes these values to instances of the ``bytes`` class. In Python 2,
304304
the driver decodes them to instances of the
305305
`Binary <https://pymongo.readthedocs.io/en/4.11/api/bson/binary.html#bson.binary.Binary>`__
306-
class with subtype 0. For code examples that show the differences, see the
307-
:ref:`Extended JSON <pymongo-serialization-binary-data>` page.
306+
class with subtype 0.
307+
308+
The following code examples show how {+driver-short+} decodes instances of the ``bytes``
309+
class. Select the :guilabel:`Python 2` or :guilabel:`Python 3` tab to view the corresponding
310+
code.
311+
312+
.. tabs::
313+
314+
.. tab:: Python 2
315+
:tabid: python2
316+
317+
.. io-code-block::
318+
:copyable: true
319+
320+
.. input::
321+
:language: python
322+
323+
from pymongo import MongoClient
324+
325+
client = MongoClient()
326+
client.test.test.insert_one({'binary': b'this is a byte string'})
327+
doc = client.test.test.find_one()
328+
print(doc)
329+
330+
.. output::
331+
332+
{u'_id': ObjectId('67afb78298f604a28f0247b4'), u'binary': Binary('this is a byte string', 0)}
333+
334+
.. tab:: Python 3
335+
:tabid: python3
336+
337+
.. io-code-block::
338+
:copyable: true
339+
340+
.. input::
341+
:language: python
342+
343+
from pymongo import MongoClient
344+
345+
client = MongoClient()
346+
client.test.test.insert_one({'binary': b'this is a byte string'})
347+
doc = client.test.test.find_one()
348+
print(doc)
349+
350+
.. output::
351+
352+
{'_id': ObjectId('67afb78298f604a28f0247b4'), 'binary': b'this is a byte string'}
308353

309354
The driver behaves the same way when decoding JSON binary values with subtype 0. In
310355
Python 3, it decodes these values to instances of the ``bytes`` class. In Python 2,

0 commit comments

Comments
 (0)