0

我正在使用以下语法建立与我的副本集的连接:

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

我究竟做错了什么?

4

1 回答 1

2

改为这样做:

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

请参阅连接字符串文档:

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

于 2017-02-08T12:16:12.563 回答