我在用着MongoDB shell version v4.4.0 和 pymongo 3.10.0版本当我使用any_db.any_collection.count()或any_db.any_collection.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 print(f'Total Categories = {db.rank_list_category.count({})}') 我的代码:import pandas as pdfrom src.utils import get_full_pathfrom pymongo import MongoClientfrom bson.objectid import ObjectIdclient = MongoClient('localhost', 27017)db = client['techexpert']print(f'Total Categories = {db["rank_list_category"].count({})}')输出:Total Categories = 5 /home/mobin/PycharmProjects/IMDb/src/database/database_service_provider.py:17: 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 print(f'Total Categories = {db.rank_list_category.count({})}')
2 回答
临摹微笑
TA贡献1982条经验 获得超2个赞
如文档中所述
count() 方法已弃用,在事务中不受支持。请改用 count_documents() 或 estimated_document_count() 。
从 count() 迁移到 count_documents() 时,必须替换以下查询运算符 - $where、$near、$nearSphere
在 3.7 版更改:不推荐使用。
所以使用count_documents
当年话下
TA贡献1890条经验 获得超9个赞
您收到此警告是因为pymongo
弃用了该count
函数,这意味着您不应再在新代码中使用它。
改变你的用途:
db.collection.count({})
到
db.collection.count_documents({})
添加回答
举报
0/150
提交
取消