適用於mongo使用SCRAM-SHA-1認證的連接方式
網上有很多這樣的,但是代碼太多,我這裏儘量代碼簡練有能用
class ip:
def __init__(self):
myclient = pymongo.MongoClient(host="49.232.72.229", port=27017)
mydb = myclient['ip']
mydb.authenticate("lihang", "23456lh..", mechanism='SCRAM-SHA-1')
print("successed")
self.mycol = mydb['agent']
然後直接操作self.mycol 即可增刪改差