code: def monkey_patch_bson(bson=None):
    '''Patch bson in pymongo to use loads and dumps interface.'''
    if not bson:
      import bson
  
    if not hasattr(bson, 'loads'):
      bson.loads = lambda bsondoc: bson.BSON(bsondoc).decode()
  
    if not hasattr(bson, 'dumps'):
      bson.dumps = lambda document: bson.BSON.encode(documentf monkey_patch_bson(bson=None):
    '''Patch bson in pymongo to use loads and dumps interface.'''
    if not bson:
      import bson
  
    if not hasattr(bson, 'loads'):
      bson.loads = lambda bsondoc: bson.BSON(bsondoc).decode()
  
    if not hasattr(bson, 'dumps'):
      bson.dumps = lambda document: bson.BSON.encode(document)
docs: Patch bson in pymongo to use loads and dumps interface.