TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘authenticate‘ method
Posted Circle-C
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘authenticate‘ method相关的知识,希望对你有一定的参考价值。
使用pymongo连接MongoDB用户认证
self.client = pymongo.MongoClient(host="127.0.0.1", port=27017)
self.client["admin"].authenticate("admin", "12345678")
在3.9版本及以前是正常运行的,而在4.0版本出错:
TypeError: 'Collection' object is not callable. If you meant to call the 'authenticate' method on a 'Database' object it is failing because no such method exists.
原因是4.0版本做了修改
4.0文档地址:PyMongo 4 Migration Guide — PyMongo 4.0.1 documentation
解决办法:
更新代码
client = pymongo.MongoClient(host="127.0.0.1", port=27017,username="admin",password="12345678")
或者退回到4.0之前的版本
先使用
pip uninstall pymongo
输入y进行删除
然后再次安装时指定pymongo的版本为3.9
pip install pymongo==3.9
以上是关于TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘authenticate‘ method的主要内容,如果未能解决你的问题,请参考以下文章
Node js & mongoDB - TypeError: db.collection is not a function
TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘authenticate‘ method
TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘authenticate‘ method
TypeError: ‘Collection‘ object is not callable. If you meant to call the ‘insert‘ method on a ‘Datab
TypeError:无法读取未定义的属性(读取“集合”)-Vuejs 和 Firebase
Scipy hstack 导致“TypeError:类型不支持转换:(dtype('float64'),dtype('O'))”