Skip to content

Instantly share code, notes, and snippets.

@mitsuhiko
Created May 4, 2012 13:43
Show Gist options
  • Save mitsuhiko/2594874 to your computer and use it in GitHub Desktop.
Save mitsuhiko/2594874 to your computer and use it in GitHub Desktop.
This destroys data :-(
class Model(object):
...
def save(self, ops=None):
ops = dict(ops or ())
for column in self.modified_columns:
ops.setdefault('$set', {})[column] = self.data[column]
rv = self.collection.find_and_modify({'_id': self.id}, ops)
self.data.update(rv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment