graphene-mongo icon indicating copy to clipboard operation
graphene-mongo copied to clipboard

graphene-mongo not compatible with pymongo 4.0 or above

Open leonardwellthy opened this issue 3 years ago • 1 comments

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

leonardwellthy avatar Apr 25 '22 22:04 leonardwellthy

yes, its working when line is changed to:

count = mongoengine.get_db()[self.model._get_collection_name()].count_documents(args_copy)

krawalli avatar Apr 29 '22 19:04 krawalli