Skip to content

Commit 57da6e3

Browse files
committed
PYTHON-2790 Fix doctest issues in raw_bson
1 parent b6d1eb3 commit 57da6e3

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

bson/raw_bson.py

+13-16
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,33 @@
1919
2020
Example: Moving a document between different databases/collections
2121
22-
.. testsetup::
23-
from pymongo import MongoClient
24-
client = MongoClient(document_class=RawBSONDocument)
25-
client.drop_database('db')
26-
client.drop_database('replica_db')
27-
2822
.. doctest::
2923
3024
>>> import bson
3125
>>> from pymongo import MongoClient
3226
>>> from bson.raw_bson import RawBSONDocument
3327
>>> client = MongoClient(document_class=RawBSONDocument)
28+
>>> client.drop_database('db')
29+
>>> client.drop_database('replica_db')
3430
>>> db = client.db
3531
>>> result = db.test.insert_many([{'a': 1},
3632
... {'b': 1},
3733
... {'c': 1},
3834
... {'d': 1}])
3935
>>> replica_db = client.replica_db
4036
>>> for doc in db.test.find():
41-
... print(f"raw document: {doc.raw}")
42-
... print(f"decoded document: {bson.decode(doc.raw)}")
37+
... print("raw document: %r" % (doc.raw,))
4338
... result = replica_db.test.insert_one(doc)
44-
raw document: b'...'
45-
decoded document: {'_id': ObjectId('...'), 'a': 1}
46-
raw document: b'...'
47-
decoded document: {'_id': ObjectId('...'), 'b': 1}
48-
raw document: b'...'
49-
decoded document: {'_id': ObjectId('...'), 'c': 1}
50-
raw document: b'...'
51-
decoded document: {'_id': ObjectId('...'), 'd': 1}
39+
raw document: '...'
40+
raw document: '...'
41+
raw document: '...'
42+
raw document: '...'
43+
>>> for doc in replica_db.test.find(projection={'_id': 0}):
44+
... print("decoded document: %r" % (bson.decode(doc.raw),))
45+
decoded document: {u'a': 1}
46+
decoded document: {u'b': 1}
47+
decoded document: {u'c': 1}
48+
decoded document: {u'd': 1}
5249
5350
For use cases like moving documents across different databases or writing binary
5451
blobs to disk, using raw BSON documents provides better speed and avoids the

0 commit comments

Comments
 (0)