raw_bson – Tools for representing raw BSON documents.

Tools for representing raw BSON documents.

  • bson.rawbson.DEFAULT_RAW_BSON_OPTIONS = CodecOptions(documentclass=, tz_aware=False, uuid_representation=PYTHON_LEGACY, unicode_decode_error_handler='strict', tzinfo=None, type_registry=TypeRegistry(type_codecs=[], fallback_encoder=None))
  • The default CodecOptions forRawBSONDocument.

  • class bson.rawbson.RawBSONDocument(_bson_bytes, codec_options=None)
  • Create a new RawBSONDocument

RawBSONDocument is a representation of a BSON document thatprovides access to the underlying raw BSON bytes. Only when a field isaccessed or modified within the document does RawBSONDocument decodeits bytes.

RawBSONDocument implements the Mapping abstract baseclass from the standard library so it can be used like a read-onlydict:

  1. >>> raw_doc = RawBSONDocument(BSON.encode({'_id': 'my_doc'}))
  2. >>> raw_doc.raw
  3. b'...'
  4. >>> raw_doc['_id']
  5. 'my_doc'

Parameters:

Changed in version 3.8: RawBSONDocument now validates that the bson_bytespassed in represent a single bson document.

Changed in version 3.5: If a CodecOptions is passed in, itsdocument_class must be RawBSONDocument.

  • items()
  • Lazily decode and iterate elements in this document.

  • raw

  • The raw BSON bytes composing this document.