def post(self):
if db.users.find({"email": email}).count() != 0:
abort(400, message="email is alread used.")
DeprecationWarning: count is deprecated. Use Collection.count_documents instead.
I'm making authentication server with Python-Flask and PyMongo package. Every time post() method is called, above deprecation warning message is displayed.
def post(self):
if db.users.find({"email": email}).count_documents() != 0:
abort(400, message="email is alread used.")
However, if I change count() to count_documents(), following error message comes out.
AttributeError: 'Cursor' object has no attribute 'count_documents'
How do I call count_documents() correctly after find() is called?
The method count_documents is part of the collection, not the cursor (find returns a cursor).
Please see the PyMongo documentation regarding the method for more information and a note regarding some operators.
def post(self):
if db.users.count_documents({"email": email}) != 0:
abort(400, message="email is alread used.")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With