django-renjith
django-renjith

Reputation: 4010

Connection refused while trying to use pymongo

I installed pymongo in my bottle virtualenv. I tried to use it but got the following error:

connection = Connection()
---------------------------------------------------------------------------
ConnectionFailure                         Traceback (most recent call last)
<ipython-input-9-609d5cb538f5> in <module>()
----> 1 connection = Connection()

/home/python/BENV/local/lib/python2.7/site-packages/pymongo/connection.pyc in __init__(self, host, port, max_pool_size, network_timeout, document_class, tz_aware, _connect, **kwargs)
    234 
    235         super(Connection, self).__init__(host, port,
--> 236                 max_pool_size, document_class, tz_aware, _connect, **kwargs)
    237 
    238     def __repr__(self):

/home/python/BENV/local/lib/python2.7/site-packages/pymongo/mongo_client.pyc in __init__(self, host, port, max_pool_size, document_class, tz_aware, _connect, **kwargs)
    367             except AutoReconnect, e:
    368                 # ConnectionFailure makes more sense here than AutoReconnect
--> 369                 raise ConnectionFailure(str(e))
    370 
    371         if username:

ConnectionFailure: [Errno 111] Connection refused

Why did I get this error and how do I fix it?

Upvotes: 0

Views: 846

Answers (1)

Asya Kamsky
Asya Kamsky

Reputation: 42352

When you don't specify the host and port to connect to like you did by passing nothing to Connection connection = Connection() the driver tries to connect to port 27017 on localhost.

Since it failed, it strongly suggests you are not running a mongod process on the same machine pymongo is running on that's listening to port 27017.

If you already have a MongoDB server that you want to connect to, you must specify its location - host and port passed to Connection.

Upvotes: 1

Related Questions