Added full_result kwarg to update (#380)

This commit is contained in:
Ross Lawley
2013-06-21 10:19:40 +00:00
parent 574f3c23d3
commit f1a1aa54d8
4 changed files with 37 additions and 7 deletions

View File

@@ -353,7 +353,13 @@ class Document(BaseDocument):
been saved.
"""
if not self.pk:
raise OperationError('attempt to update a document not yet saved')
if kwargs.get('upsert', False):
query = self.to_mongo()
if "_cls" in query:
del(query["_cls"])
return self._qs.filter(**query).update_one(**kwargs)
else:
raise OperationError('attempt to update a document not yet saved')
# Need to add shard key to query, or you get an error
return self._qs.filter(**self._object_key).update_one(**kwargs)