Reputation: 49
I'm having the following problem with PyMongo 3.0. Did anyone find out how to fix this problem?
from pymongo import MongoClient
# making a Connection with MongoClient
client = MongoClient()
# getting a Database
db = client.test_database
# getting a Collection
test = db['test-collection']
client['test-collection']
print client('test-collection')
---Database(MongoClient('localhost', 27017), u'test-collection')
# inserting a document
test.insert_one({"test": True})
This is the error:
File "/usr/local/lib/python2.7/dist-packages/pymongo/topology.py", line 113, in select_server
server_selection_timeout))
File "/usr/local/lib/python2.7/dist-packages/pymongo/topology.py", line 93, in select_servers
self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused
Edit 1:
I get the same error when I try to execute the MongoDB interactive shell:
# making a Connection with MongoClient
client = MongoClient()
client.database_names()
SOLVED:
I found the following error in /var/log/mongodb:
[initandlisten] exception in initAndListen: 15926 Insufficient free space for journals, terminating
It seems I have no enough free disk in my VM so my mongodb it wasn't running on my machine.
I finally I found the solution to this problem in the following post: Why getting error mongod dead but subsys locked and Insufficient free space for journal files on Linux?
It seems that the problem can be solved using smallfiles property in mongodb log file.
Upvotes: 3
Views: 8382
Reputation: 723
I believe that you are having this error because you don't have mongo db running on your machine at port 27017. It seems that PyMongo only tries to connect to the server on the insert command.
Verify if the Mongodb server is running on localhost in port 27017 or pass to the MongoClient constructor the correct address and por if different of localhost 27017
Upvotes: 1