graphene-mongo
graphene-mongo copied to clipboard
graphene-mongo not compatible with pymongo 4.0 or above
Error message
Running the tutorial example at https://graphene-mongo.readthedocs.io/en/latest/tutorial.html returns the following error
{
"errors": [
{
"message": "'Cursor' object has no attribute 'count'",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"allEmployees"
]
}
],
"data": {
"allEmployees": null
}
}
Underlying cause
pymongo.cursor.Cursor.count() was deprecated in pymongo 3.7.0 and removed in pymongo 4.0. See the pymongo changelogs
Solution
The following line in fields.py needs to be replaced with a call to pymongo.collection.Collection.count_documents
count = mongoengine.get_db()[self.model._get_collection_name()].find(args_copy).count()
Temporary workaround
pip install pymongo==3.12.0
yes, its working when line is changed to:
count = mongoengine.get_db()[self.model._get_collection_name()].count_documents(args_copy)