1
votes

I am trying to connect to my MongoDB database in localhost. While I type mongo in command shell I am getting an error in the command shell:

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:341:17

6
It may mean that your MongoDB server is not running. First, you should run it, and it would work.pntripathi9417
Can you please be a little more detail, how can I run it?tanvirgeek
Yes, I had to run it in another shell by mongod command, then working nicely. Even though I had set the environment variable, I have to recheck it.tanvirgeek

6 Answers

1
votes

command mongod will run the MongoDB server using the default configuration. You can change these configurations by locating the default path of the configuration files.

2
votes

This will start the mongo server as a service:

brew services start mongodb-community
1
votes

The primary daemon process for the MongoDB database system is called mongod. You need to start this service before making connection attempts.

You can do this in Ubuntu by:

sudo service mongod start

or,

sudo systemctl start mongod

Start mongod on system boot by:

systemctl enable mongodb.service
0
votes

I had the same issue. When running mongod command, it mentioned the C:/data/db as E:/data/db path. After I created the folder in mentioned E:/data/db path it works!

0
votes

For windows user

1. Type ctrl + r

Type ctrl + r

mongodb server

2. Scroll to mongodb server

3. start the server
0
votes

do you have a linux distro? If you do, the solution is a bit annoying as you have to do it everytime you start your pc. The solution is:

  1. Type "mongo" and "mongod" once in the terminal. It will show an error, don't worry, that's the whole point

  2. type this:

    chown -R mongodb:mongodb /var/lib/mongodb

    chown mongodb:mongodb /tmp/mongodb-27017.sock

    sudo service mongod restart

tip: copy the whole thing and paste on the terminal using ctrl+shift+v. You're welcome :-)