pymongo 4.0的‘Cursor‘ object has no attribute ‘count‘异常

Posted 何小有

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pymongo 4.0的‘Cursor‘ object has no attribute ‘count‘异常相关的知识,希望对你有一定的参考价值。

pymongo 模块的 Cursor 对象在 2021年11月30日‎ 之后因为更新到 4.0 版本,删除了 Cursor 类里的 count 方法,以下是 4.0 和 3.12.2 两个版本的 Cursor 类对比:

https://github.com/mongodb/mongo-python-driver/blob/4.0/pymongo/cursor.py

https://github.com/mongodb/mongo-python-driver/blob/3.12.2/pymongo/cursor.py

最快的解决方案是:指定一下 pymongo 的版本,不要使用最新的 4.0 版本

以上是关于pymongo 4.0的‘Cursor‘ object has no attribute ‘count‘异常的主要内容,如果未能解决你的问题,请参考以下文章