Mongodb – Does not start MongoDB 4

mongodb

I just started learning MongoDB. When I run for the first time, I get an error.
MongoDB 4 version
Windows 10 x64

MongoDB shell version v4.0.1
connecting to: mongodb://127.0.0.1:27017
2018-08-13T00:15:54.149+0300 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: No connection could be made because the target machine actively refused it. :
connect@src/mongo/shell/mongo.js:257:13
@(connect):1:6
exception: connect failed

Best Answer

Make sure you created the /data/db at the root. otherwise, do the simple steps.

For Mac or Linux user

1 - first open the terminal as root.

sudo bash

2 - make db folder

mkdir -p /data/db

3 - give the chmod 777 to the directory.

chmod 777 /data
chmod 777 /data/db

4 - confirm the /data/db is 777

ls -ld /data/db

5 - exit the root shell

6 - run the mongod cmd at mongodb_path/bin directory.

mongod

make sure it is listing port. By default, it listens to the 27017 port.

7- open the new terminal window and run the mongo cmd at mongodb_path/bin directory.

mongo

For window user

1- create the /data/db at like C:\data\db

2- open the terminal at mongodb_path/bin

mongod

make sure it is listing port. By default, it listens to the 27017 port.

3- open the new terminal window at mongodb_path/bin

mongo
Related Topic