簡體   English   中英

pymongo ReplicaSet用戶名密碼

[英]pymongo ReplicaSet username password

我正在使用以下語法來建立與副本集的連接:

from urllib.parse import quote
mongo_client = pymongo.MongoClient(host=[
    quote('username:password@ipaddress1:27017'),
    quote('username:password@ipaddress2@10.0.5.65:27017'),
    quote('username:password@ipaddress3@10.0.2.176:27017')],
                                    connect=False,
replicaset="enterprise")

但是,當我嘗試插入這樣的文檔時:

db = mongo_client.test
db.test.insert_one({"test": "test"})

我收到了pymongo ServerSelectionTimeOutError:名稱或服務未知

我究竟做錯了什么?

改為這樣做:

MongoClient('mongodb://username:password@ipaddress1,ipaddress2,ipaddress3/?replicaSet=enterprise')

請參閱連接字符串文檔:

https://docs.mongodb.com/manual/reference/connection-string/#standard-connection-string-format

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM