python中mongodb查询指定字段值是否存在的方法:
import pymongo # 链接数据库 client = pymongo.MongoClient(host='127.0.0.1', port=27017) # 数据库登录需要帐号密码的话 client.runoob.authenticate('runoob', 'runoob',mechanism='SCRAM-SHA-1') db = client['runoob'] # 获得数据库的句柄 coll = db['details'] # 获得collection的句柄 # python中mongodb判断某字段的值是否存在 count = coll.count_documents({ "articleid": "d5a603693d943e77be0c9901a92cce28" }) if count !=0: print("有")
更多Python知识请关注Python自学网