diff --git a/asyncio_mongo/pool.py b/asyncio_mongo/pool.py index 425fc86..0bc54c1 100644 --- a/asyncio_mongo/pool.py +++ b/asyncio_mongo/pool.py @@ -54,7 +54,7 @@ class Pool: except (AttributeError, ValueError): raise Exception("Missing database name in URI") - self._host = url.hostname + host = url.hostname try: port = url.port @@ -63,10 +63,15 @@ class Pool: # strip any additional hosts in the connection string for now try: if "," in port: - port = port[:port.find(',')] + hosts = port.split(",") + netloc = hosts[len(hosts)-1] + netloc = netloc.split(':') + host = netloc[0] + port = netloc[1] except TypeError: pass + self._host = host self._port = port or 27017 username = url.username password = url.password diff --git a/tests/test_connection.py b/tests/test_connection.py index d479f74..dad6156 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -45,7 +45,7 @@ class TestMongoConnectionMethods(MongoTest): @async def test_pool_multiple_hosts(self): # MongoConnectionPool returns deferred, which gets MongoAPI - pool = asyncio_mongo.Pool.create(url="mongodb://{host}:{port},otherhost:333".format( + pool = asyncio_mongo.Pool.create(url="mongodb://blahhost:333,{host}:{port}".format( host=mongo_host, port=mongo_port), poolsize=2) self.assertTrue(inspect.isgenerator(pool)) rapi = yield from pool