raw_bson
– Tools for representing raw BSON documents.
Example: Moving a document between different databases/collections
For use cases like moving documents across different databases or writing binary blobs to disk, using raw BSON documents provides better speed and avoids the overhead of decoding or encoding BSON.
bson.raw_bson.DEFAULT_RAW_BSON_OPTIONS
= CodecOptions(document_class=<class ‘bson.raw_bson.RawBSONDocument’>, tz_aware=False, uuid_representation=UuidRepresentation.PYTHON_LEGACY, unicode_decode_error_handler=’strict’, tzinfo=None, type_registry=TypeRegistry(type_codecs=[], fallback_encoder=None))
The default CodecOptions for .
Create a new RawBSONDocument
is a representation of a BSON document that provides access to the underlying raw BSON bytes. Only when a field is accessed or modified within the document does RawBSONDocument decode its bytes.
RawBSONDocument implements the Mapping
abstract base class from the standard library so it can be used like a read-only :
>>> from bson import encode
>>> raw_doc = RawBSONDocument(encode({'_id': 'my_doc'}))
b'...'
'my_doc'
Changed in version 3.8: now validates that the bson_bytes
passed in represent a single bson document.
items
()Lazily decode and iterate elements in this document.
-
The raw BSON bytes composing this document.