I created the following Mongo replicas using mongo cli:
> config = { _id:"repset", members:[{_id:0,host:"192.168.0.1:27017"},{_id:1,host:"192.168.0.2:27017"},{_id:2,host:"192.168.0.3:27017"}]} > rs.initiate(config);
All mongo servers are working correctly.
>>> import pymongo >>> from pymongo import MongoClient >>> servers = ["192.168.0.1:27017", "192.168.0.2:27017", "192.168.0.3:27017"] >>> MongoClient(servers) >>> xc = MongoClient() >>> print xc MongoClient('localhost', 27017) >>> print xc.database_names() [u'test_repsets', u'local', u'admin', u'test']
After I kill the local mongodb server, it shows me a connection timeout error:
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
There seems to be no automatic failure, although I defined the mongodb server. I am wondering if pymongo handles the failure automatically, or how is this situation handled properly?
Thanks in advance.
source share