code: def save_object(collection, obj):
      
      if 'id' not in obj:
          obj.id = uuid()
      id = obj.id
      path = object_path(collection, id)
      temp_path = '%s.temp' % path
      with open(temp_path, 'w') as f:
          data = _serialize(obj)
          f.write(data)
      shutil.move(temp_path, path)
      if id in _db[collection].cache:
          _db[collection].cache[id] = obj
      _update_indexes_for_mutated_object(collection, obj)
      return obj
docs: Save an object ``obj`` to the given ``collection``.
  
      ``obj.id`` must be unique across all other existing objects in
      the given collection.  If ``id`` is not present in the object, a
      *UUID* is assigned as the object's ``id``.
  
      Indexes already defined on the ``collection`` are updated after
      the object is saved.
  
      Returns the object.