亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 python 中使用 pymongo 使用 db.collection.count()

在 python 中使用 pymongo 使用 db.collection.count()

夢里花落0921 2023-06-06 17:34:29
我在用著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


查看完整回答
反對 回復 2023-06-06
?
當年話下

TA貢獻1890條經驗 獲得超9個贊

您收到此警告是因為pymongo棄用了該count函數,這意味著您不應再在新代碼中使用它。

改變你的用途:

db.collection.count({})

db.collection.count_documents({})


查看完整回答
反對 回復 2023-06-06
  • 2 回答
  • 0 關注
  • 330 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號