加入收藏 | 设为首页 | 会员中心 | 我要投稿 北几岛 (https://www.beijidao.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2021-05-21 04:54:54 所属栏目:大数据 来源: https://blog.csdn.net/yilovex
导读:最近老代码重构,使用的新版本 MongoDB,Python3.7 安装 pymongo 模块,在使用 count 统计数据量的时候报了一个警告: DeprecationWarning: count is deprecated. Use estimated_document_count or count_documents instead. Please note that $where must b

最近老代码重构,使用的新版本 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})

(编辑:北几岛)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读