code: def transform_incoming(self, son, collection):
          
          for (key, value) in son.items():
              if isinstance(value, dict):  # Make sure we recurse into sub-docs
                  son[key] = self.transform_incoming(value, collection)
              elif hasattr(value, 'serialize'):
                  LOG.debug("Serializing object: %s", value)
                  son[key] = value = value.serialize()
          return son
docs: Recursively replace all keys that need transforming.
  
          This will serialize all objects that have a
          serialize method before sending them to mongo.