0

I'm using the following syntax to establish a connection to my replica set:

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")

However when I try to insert a document like this:

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

I get a pymongo ServerSelectionTimeOutError: Name or service not known

What am I doing wrong?

masterforker
  • 2,443
  • 2
  • 25
  • 39

1 Answers1

2

Do this instead:

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

See the connection string docs:

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

A. Jesse Jiryu Davis
  • 23,641
  • 4
  • 57
  • 70