A
A
Alexey Poloz2017-10-23 15:29:35
Python
Alexey Poloz, 2017-10-23 15:29:35

Python MongoDB Why can't start local server?

I run the simplest code:

from pymongo import *
db = MongoClient()['db']
table = db['table']
table.save({1:'blabla'})

He thinks for a while and gives an error:
On MacOS this:
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 61] Connection refused

On Linux like this:
pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused

What is wrong and how to do it right?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Poloz, 2017-10-23
@kosyachniy

To perform operations with the database, the MobgoDB server must be running.
For Linux:

lsof -i:27017
sudo apt-get install mongodb
sudo service mongodb start
tail -n200 /var/log/mongodb/mongodb.log

For macOS:
brew update
brew install mongodb
mkdir -p /data/db
sudo chmod -R 777 /data/db
mongod

And leave this window
Run the program in another process

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question