Pymongo 3.0 issues (ServerSelectionTimeoutError)

I have a problem with PyMongo 3.0. Has anyone found 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 mistake:

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

      

DECIDE:

I encountered the following error in / var / log / mongodb:

[initandlisten] exception in initAndListen: 15926 Insufficient free space for journals, terminating

      

I seem to be running out of free disk in my virtual machine, so my mongodb was not working on my machine.

Finally, I found a solution to this problem in the following post: Why is there a mongod dead error but subsys is locked and there is not enough free space for log files in Linux?

It seems like the problem can be solved by using the smallfiles property in the mongodb log file.

+3


source to share


1 answer


I believe you have this error because you don't have a mongo db on your machine at port 27017. It seems that PyMongo is only trying to connect to the server in the insert command.



Make sure Mongodb server is running on localhost at port 27017 or pass the correct address and por to MongoClient constructor if different from localhost 27017

0


source







All Articles