removed deprecated warning for 'update' method

This commit is contained in:
Calgary Michael
2018-02-02 22:04:30 -06:00
parent 9b04391f82
commit 4d5c6d11ab
3 changed files with 26 additions and 13 deletions

View File

@@ -1,9 +1,11 @@
from mongoengine.common import _import_class
from mongoengine.connection import DEFAULT_CONNECTION_NAME, get_db
from pymongo.write_concern import WriteConcern
from contextlib import contextmanager
__all__ = ('switch_db', 'switch_collection', 'no_dereference',
'no_sub_classes', 'query_counter')
'no_sub_classes', 'query_counter', 'set_write_concern')
class switch_db(object):
@@ -215,3 +217,10 @@ class query_counter(object):
count = self.db.system.profile.find(ignore_query).count() - self.counter
self.counter += 1
return count
@contextmanager
def set_write_concern(collection, write_concerns):
yield collection.with_options(write_concern=WriteConcern(
**dict(collection.write_concern.document.items()),
**write_concerns))