使用 server_info() 的 PyMongo 中的集合对象不可调用错误

Collection object is not callable error in PyMongo with server_info()

我正在将我的工作 django 项目升级到 python3.4。部署后,我遇到了以下问题!

(同一个项目在 python2.7pymongo2.8 风格下运行良好。)

我有 pymongo3.2django-mongo-sessions 以及其他图书馆

File "/home/ec2-user/py33/local/lib/python3.4/site-packages/mongo_sessions/session.py", line 8, in <module>
from mongo_sessions import settings

File "/home/ec2-user/py33/local/lib/python3.4/site-packages/mongo_sessions/settings.py", line 36, in <module>
MONGO_DB_VERSION = MONGO_CLIENT.connection.server_info()['version']

File "/home/ec2-user/py33/local/lib64/python3.4/site-packages/pymongo/collection.py", line 2348, in __call__
self.__name.split(".")[-1])

TypeError: 'Collection' object is not callable. If you meant to call the 'server_info' method on a 'Collection' object it is failing because no such method exists.

我调查了 看起来很相似的问题。但我很确定我正在使用 pymongo3.2 本身!

django-mongo-sessions 似乎尚未更新以支持 PyMongo 3.x。您的特殊问题是 Database.connection 在 PyMongo 3.0 中被重命名为 Database.client。失败的代码行应更改为:

MONGO_DB_VERSION = MONGO_CLIENT.client.server_info()['version']

这可能不是唯一需要的更改。详情见migration guide