微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python3 pymongo 使用 count 报警告解决办法

最近老代码重构,使用的新版本 MongoDB,python3.7 安装 pymongo 模块,在使用 count 统计数据量的时候报了一个警告:

DeprecationWarning: count is deprecated. Use estimated_document_count or count_documents instead. Please note that $where must be replaced by $expr,$near must be replaced by $geoWithin with $center,and $nearSphere must be replaced by $geoWithin with $centerSphere

大致意思是 count 这个统计函数在新版本 MongoDB 弃用了,改用新的统计函数

estimated_document_count()

将之前的旧版

db_count = cursor.count()

修改

db_count = cursor.estimated_document_count()

如果是带条件的查询统计就需要使用 count_documents

db_count = cursor.count_documents({'dt': handle_date})

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐