diff --git a/plugins/mongodb/index.py b/plugins/mongodb/index.py index c6b74c6f8..9025997f5 100755 --- a/plugins/mongodb/index.py +++ b/plugins/mongodb/index.py @@ -196,10 +196,11 @@ def mongdbClientS(): mg_root = pSqliteDb('config').where('id=?', (1,)).getField('mg_root') if auth == 'disabled': - client = pymongo.MongoClient(host=ip, port=int(port), directConnection=True) + client = pymongo.MongoClient(host=ip, port=int(port)) else: # print(auth,mg_root) - client = pymongo.MongoClient(host=ip, port=int(port), directConnection=True, username='root',password=mg_root) + # 使用 admin 数据库进行认证,兼容 MongoDB 3.0 + client = pymongo.MongoClient(host=ip, port=int(port), username='root', password=mg_root, authSource='admin') return client def mongdbClient(): @@ -210,11 +211,12 @@ def mongdbClient(): mg_root = pSqliteDb('config').where('id=?', (1,)).getField('mg_root') # print(ip,port,auth,mg_root) if auth == 'disabled': - client = pymongo.MongoClient(host=ip, port=int(port), directConnection=True) + client = pymongo.MongoClient(host=ip, port=int(port)) else: # uri = "mongodb://root:"+mg_root+"@127.0.0.1:"+str(port) # client = pymongo.MongoClient(uri) - client = pymongo.MongoClient(host=ip, port=int(port), directConnection=True, username='root',password=mg_root) + # 使用 admin 数据库进行认证,兼容 MongoDB 3.0 + client = pymongo.MongoClient(host=ip, port=int(port), username='root', password=mg_root, authSource='admin') return client diff --git a/plugins/mongodb/scripts/backup.py b/plugins/mongodb/scripts/backup.py index bc3db6bf1..e6f64a324 100644 --- a/plugins/mongodb/scripts/backup.py +++ b/plugins/mongodb/scripts/backup.py @@ -122,11 +122,12 @@ def mongdbClient(): mg_root = pSqliteDb('config').where('id=?', (1,)).getField('mg_root') # print(ip,port,auth,mg_root) if auth == 'disabled': - client = pymongo.MongoClient(host=ip, port=int(port), directConnection=True) + client = pymongo.MongoClient(host=ip, port=int(port)) else: # uri = "mongodb://root:"+mg_root+"@127.0.0.1:"+str(port) # client = pymongo.MongoClient(uri) - client = pymongo.MongoClient(host=ip, port=int(port), directConnection=True, username='root',password=mg_root) + # 使用 admin 数据库进行认证,兼容 MongoDB 3.0 + client = pymongo.MongoClient(host=ip, port=int(port), username='root', password=mg_root, authSource='admin') return client class backupTools: