Merge branch 'upsert' of git://github.com/blackbrrr/mongoengine

This commit is contained in:
Harry Marr 2010-03-17 12:30:18 +00:00
commit 39fc862676

View File

@ -597,7 +597,7 @@ class QuerySet(object):
return mongo_update return mongo_update
def update(self, safe_update=True, **update): def update(self, safe_update=True, upsert=False, **update):
"""Perform an atomic update on the fields matched by the query. """Perform an atomic update on the fields matched by the query.
:param safe: check if the operation succeeded before returning :param safe: check if the operation succeeded before returning
@ -611,14 +611,14 @@ class QuerySet(object):
update = QuerySet._transform_update(self._document, **update) update = QuerySet._transform_update(self._document, **update)
try: try:
self._collection.update(self._query, update, safe=safe_update, self._collection.update(self._query, update, safe=safe_update,
multi=True) upsert=upsert, multi=True)
except pymongo.errors.OperationFailure, err: except pymongo.errors.OperationFailure, err:
if unicode(err) == u'multi not coded yet': if unicode(err) == u'multi not coded yet':
message = u'update() method requires MongoDB 1.1.3+' message = u'update() method requires MongoDB 1.1.3+'
raise OperationError(message) raise OperationError(message)
raise OperationError(u'Update failed (%s)' % unicode(err)) raise OperationError(u'Update failed (%s)' % unicode(err))
def update_one(self, safe_update=True, **update): def update_one(self, safe_update=True, upsert=False, **update):
"""Perform an atomic update on first field matched by the query. """Perform an atomic update on first field matched by the query.
:param safe: check if the operation succeeded before returning :param safe: check if the operation succeeded before returning
@ -632,7 +632,7 @@ class QuerySet(object):
# as the default may change to 'True' # as the default may change to 'True'
if pymongo.version >= '1.1.1': if pymongo.version >= '1.1.1':
self._collection.update(self._query, update, safe=safe_update, self._collection.update(self._query, update, safe=safe_update,
multi=False) upsert=upsert, multi=False)
else: else:
# Older versions of PyMongo don't support 'multi' # Older versions of PyMongo don't support 'multi'
self._collection.update(self._query, update, safe=safe_update) self._collection.update(self._query, update, safe=safe_update)