[英]How to check if given data exist or Not in mongodb and python
我使用了下面的代码。
from pymongo import MongoClient
client=MongoClient()
db=client.mydb
if db.mycollections.find({"name": 'Chinna',"password":'chinna11'}).count() > 0:
print("true")
else:
print("false")
但它返回低于错误,
DeprecationWarning: count is deprecated. Use Collection.count_documents instead.
如果有人知道,请帮助..
假设您对文档不感兴趣,只对匹配的文档不感兴趣,请用.count_documents() 替换.find():
from pymongo import MongoClient
client=MongoClient()
db=client.mydb
if db.mycollections.count_documents({"name": 'Chinna',"password":'chinna11'}) > 0:
print("true")
else:
print("false")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.