http://api.mongodb.com/python/3.4.0/api/pymongo/collection.html shows the following methods as deprecated: insert, save, update, remove, find_and_modify, ensure_index. We still use those in our codebase.
We should appropriately utilize the new insert_one, insert_many, replace_one, update_one, update_many, delete_one, delete_many, find_one_and_delete, find_one_and_replace, and find_one_and_update.
This might be a very tough project, because we'll have to conditionally support both the old collection methods for PyMongo v2.7-2.9 and new collection methods for v3.x, and ideally maintain near-identical behavior from the MongoEngine user's point of view.
remove from the list above.Is this possible to use mongoengine in any way to avoid that deprecation warnings?
Mark
Has there been any progress?
Is it an option to drop support for PyMongo < 3? Version 3.0 has been released 2015-04. This would make the task much simpler.
I would agree with the last comment.
Today it is not possible to update MongoDB to 3.2 or 3.4 if you heavily rely on Mongoengine, which leads to more and more security/performance debt.
Would people be interested in a PR, which drops support for PyMongo < 3?
I use this routine to implement the save logic using the recommended methods.
Used insert_one and replace_one instead of save
Hi all,
Mongoengine keeps throwing a deprecation warning for for the save method -when updating an existing record - with the following versions of Mongoengine and Pymongo, respectively:
mongoengine 0.16.3
more-itertools 5.0.0
pip 19.0.2
pluggy 0.8.1
py 1.7.0
pymongo 3.7.2
lib/python3.6/site-packages/mongoengine/document.py:503: DeprecationWarning: update is deprecated. Use replace_one, update_one or update_many instead.
upsert=upsert, **write_concern)
Not sure where you guys are at with this.
Thanks.
~
mongoengine/queryset/base.py:400:
count = self._cursor.count(with_limit_and_skip=with_limit_and_skip)`
~
generates a DeprecationWarning on PyMongo 3.x
~
/mongoengine/queryset/base.py:400: DeprecationWarning: count is deprecated. Use Collection.count_documents instead.
count = self._cursor.count(with_limit_and_skip=with_limit_and_skip)
~
Given mongo's change to Collection.count_documents() it seems like we have to use _query here instead of _cursor.
count is a common functionality and it's even featured prominently in the quick start tutorial in the repo README
~~~
BlogPost.objects.count()
2
TextPost.objects.count()
1
LinkPost.objects.count()
1
~~~
it's probably not so good for the README code to create DeprecationWarnings
If this isn't a duplicate I can make a PR.
Hi @yueranyuan, its worth fixing, feel free to open a PR. Consider using the backward compatible function defined in from mongoengine.pymongo_support import count_documents
I would like to know if I should continue using save, update and other deprecated functions. Or I should use only the new ones mentioned?
The question arises because whole Documentation (tutorial and API) uses the deprecated ones and I don't find a single example of how to use the new ones,
Unless you have a problem with the deprecation warning, I'd advise you to continue using save, etc (inside MongoEngine).
Pymongo hasn't dropped the support so its relatively harmless. MongoEngine will do the switch as some point. Note that the warning issued by .count is addressed in an existing MR
Most helpful comment
Would people be interested in a PR, which drops support for PyMongo < 3?