user13476
user13476

Reputation: 97

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

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?

Upvotes: 7

Views: 69565

Answers (10)

my problem is the connectoon is down, run script:

brew services start mongodb-community

And up mongoDB Compass and works.

Upvotes: 0

Deotyma
Deotyma

Reputation: 940

I had the same problem on my Mac. I updated my Homebrew files, after I reinstaled MongoDB in my terminal

 brew tap mongodb/brew

and

brew install mongodb-community@5.

and I started mongo server

brew services start mongodb/brew/mongodb-community

After that I coud to commect.

Upvotes: 0

g3holliday
g3holliday

Reputation: 41

Type sudo pip3 install mongodb, then sudo pip3 install pymongo, then mongod.

Upvotes: 0

Mehrdad Harasi
Mehrdad Harasi

Reputation: 1

I ran mongodb install file and choose repair

Upvotes: -1

Adittya Verma
Adittya Verma

Reputation: 289

I got this issue because I didn't have MongoDB. So I installed MongoDB and tried to run node application and it worked.

If you don't have MongoDB then follow below steps to install and enjoy

Commands :

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927

$ echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list

$ sudo apt-get update

$ sudo apt-get install -y mongodb-org

Then type mongo in terminal and if you will get console for mongo then it's done.

Upvotes: 0

Chukwuemeka Maduekwe
Chukwuemeka Maduekwe

Reputation: 8586

on windows open task manager || Ctrl + shift + ESC > select service tab > search for mongo db > right click > start service

Upvotes: 1

I think that you don't have an environmental variable declared. Assuming that your MongoDB installation is C:\ProgramFiles\MongoDB\Server\YOUR_VERSION_NUMBER\, you should just add the bin folder path of that version of MongoDB to your PATH system environment variable.

Here's a link where you can find the way to do that without complications : http://www.computerhope.com/issues/ch000549.htm

Upvotes: 2

Shubham Shinde
Shubham Shinde

Reputation: 171

  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.

Upvotes: 17

After installing MongoDb you have to add the directory "data\db" under the C:\ directory, then you should start the mongod.exe

Upvotes: 1

SomeKittens
SomeKittens

Reputation: 39522

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.

Upvotes: 6

Related Questions