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: Name or service not known

我做错了什么?

改为这样做:

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

查看连接字符串文档:

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