codec_options – Tools for specifying BSON codec options

Tools for specifying BSON codec options.

class bson.codec_options.CodecOptions

Encapsulates BSON options used in CRUD operations.

Parameters:
  • document_class: BSON documents returned in queries will be decoded to an instance of this class. Must be a subclass of MutableMapping. Defaults to dict.

  • tz_aware: If True, BSON datetimes will be decoded to timezone aware instances of datetime. Otherwise they will be naive. Defaults to False.

  • uuid_representation: The BSON representation to use when encoding and decoding instances of UUID. Defaults to PYTHON_LEGACY.

  • unicode_decode_error_handler: The error handler to use when decoding

    an invalid BSON string. Valid options include ‘strict’, ‘replace’, and ‘ignore’. Defaults to ‘strict’.

Warning

Care must be taken when changing
unicode_decode_error_handler from its default value (‘strict’). The ‘replace’ and ‘ignore’ modes should not be used when documents retrieved from the server will be modified in the client application and stored back to the server.
  • tzinfo: A tzinfo subclass that specifies the timezone to/from which datetime objects should be encoded/decoded.