peterbe / django-mongokit

Bridging Django to MongoDB with the MongoKit ODM (Object Document Mapper)
Other
122 stars 20 forks source link

How to resolve depericated warning for safe parameter in save method? #17

Open AvadootNachankar opened 11 years ago

AvadootNachankar commented 11 years ago

In [1]: from gnowsys_ndf.ndf.models import *

In [2]: from django_mongokit import get_database

In [3]: from bson import ObjectId

In [4]: db = get_database()

In [5]: db.collection_names() Out[5]: [u'system.indexes']

In [6]: c_author = db[Author.collection_name]

In [7]: c_author Out[7]: Collection(Database(ConnectionWrapper: MongoClient('localhost', 27017), u'example'), u'Authors')

In [8]: o_author = c_author.Author()

In [9]: o_author Out[9]: {'created_at': datetime.datetime(2013, 9, 17, 10, 18, 8, 709583), 'name': None}

In [10]: o_author.name = u"ndf"

In [11]: o_author Out[11]: {'created_at': datetime.datetime(2013, 9, 17, 10, 18, 8, 709583), 'name': u'ndf'}

In [12]: o_author.save() /home/tissavadoot/Desktop/Tissproject/TP_MK/local/lib/python2.7/site-packages/pymongo/collection.py:266: DeprecationWarning: The safe parameter is deprecated. Please use write concern options instead. return self.insert(to_save, manipulate, safe, check_keys, **kwargs)

shuding commented 8 years ago

You could use the write_options option to avoid this warning:

o_author.save(safe=None, write_options={"w": 0})