Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongoDB error: Error: failed to connect to [localhost:27017]

Tags:

mongodb

I'm trying to install habitrpg locally but I keep getting a mongoDB error after typing node src/seed.js:

Error: failed to connect to [localhost:27017]

I saw on other questions with the same error people have suggested typing in 'mongod' and that fixes it by creating a local server. I get the error:

-bash: mongod: command not found

Can't figure out what's wrong. Any ideas?

like image 272
user13476 Avatar asked Mar 10 '14 00:03

user13476


People also ask

Why MongoDB Cannot connect to localhost?

MongoDB failed to connect to localhost 27017 macThis error occurs when the MongoDB service is not running on the mac. This command will start the MongoDB services and after this, you have to simply write in the shell mongod command. This command will start the mongo daemon.

How do I connect to localhost 27017?

To connect to your local MongoDB, you set Hostname to localhost and Port to 27017 . These values are the default for all local MongoDB connections (unless you changed them). Press connect, and you should see the databases in your local MongoDB.

Can't connect to found database localhost 27017?

0.1 : 27017 ” is a general error message indicating that your client/driver cannot connect to a server on the specified hostname/IP and port. In this specific example, 127.0. 0.1 is the hostname or IP and 27017 is the port. Your connection from client to server is blocked by firewall or network configuration.


2 Answers

  1. Open CMD (In Windows) or terminal (In Ubuntu).

  2. type command >cd PATH_FOR_MONGODB_BIN_FOLDER

    cd C:\Program Files\MongoDB\Server\3.2\bin

    for ubuntu command will be same :

    cd /home/MongoDB/Server/3.2/bin

  3. then type command >mongod --dbpath PATH_FOR_DATA_FOLDER

    mongod --dbpath C:\data\db

    For ubuntu command will be :

    ./mongod --dbpath /home/data/db

    you can specify any folder as data folder.

  4. Wait till CMD or Terminal shows "waiting for connections"

    2016-09-01T21:38:33.170+0530 I NETWORK [initandlisten] waiting for connections on port 27017

  5. Then open new CMD or terminal window.

  6. type command >cd PATH_FOR_MONGODB_BIN_FOLDER ( same as step 3 )

    cd C:\Program Files\MongoDB\Server\3.2\bin

    Don't close previous window of cmd or teminal.

  7. then run mongodb by typing "mongo" in windows or "./mongo" in ubuntu

    mongo

    For ubuntu

    ./mongo

  8. After mongodb run successfully you can close previous CMD window.

like image 119
Shubham Shinde Avatar answered Oct 16 '22 11:10

Shubham Shinde


You don't have MongoDB installed. Follow the directions for your system to install it: http://docs.mongodb.org/manual/installation/

From the habitRPG docs:

Before starting make sure to have MongoDB, NodeJS and npm and Git installed and set up.

like image 38
SomeKittens Avatar answered Oct 16 '22 11:10

SomeKittens