Huy Tran
Huy Tran

Reputation: 4441

Can't connect to mongodb

I'm newbie about node.js and mongodb.

I have already installed mongodb, but I can't connect to mongodb.

This is my error:

Huys-MacBook-Pro:~ huy$ mongo
MongoDB shell version: 2.0.2
connecting to: test
Tue Jan  3 17:12:01 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed

Upvotes: 6

Views: 25599

Answers (9)

Dickens
Dickens

Reputation: 33

Replace the /var/lib/mongodb with your dbpath

sudo rm /var/lib/mongodb/mongod.lock sudo mongod --dbpath /var/lib/mongodb/ --repair sudo mongod --dbpath /var/lib/mongodb/ --journal

Upvotes: 0

Doris Hernandez
Doris Hernandez

Reputation: 139

This worked for me:

  1. Open two terminal windows
  2. In one window start "sudo mongod" at the end of the response you should have:

2015-08-29T11:38:18.009-0700 I NETWORK [initandlisten] waiting for connections on port 27017

  1. Other window type mongo, and everthing should be working.

Upvotes: -1

bitmill
bitmill

Reputation: 83

I also ran into this issue today. Mongo had been working fine up until this point. In case you try sudo service mongodb start and you find out the process is already running (start/running, process xxxx). The solution is:

Delete the lock file

sudo rm /var/lib/mongodb/mongod.lock

and restart service again

sudo service mongodb start

Upvotes: 6

Jorge Alfonso
Jorge Alfonso

Reputation: 1

I had same problem. Yesterday was working perfectly mongo on my mac, but today doesn't, I solved just typing in a terminal command.

brew update

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/

Upvotes: 0

Melsi
Melsi

Reputation: 1462

I had the same problem under xubuntu, had been using mongo for quite long, for some reason it could not start anymore reporting that very same error... in case anyone is in the same situation, the solution for me was to reinstall:

apt-get autoremove mongodb

apt-get install mongodb-server

Upvotes: 1

Andy Petrella
Andy Petrella

Reputation: 4345

First of all, check that your data folder exists : mongo on Win. That is

C:\> mkdir \data
C:\> mkdir \data\db

Upvotes: 2

alessioalex
alessioalex

Reputation: 63683

MongoDB is not running, and I have a wild guess that your mistake is this one: Trouble installing mongodb using Homebrew

Create the path /data/db and then try to start MongoDB again. (run mongod)

Upvotes: 7

xkeshav
xkeshav

Reputation: 54050

if you are using windows version then

first run mongod in one cmd box

C:\> cd \my_mongo_dir\bin
C:\my_mongo_dir\bin> mongod

leave it open and now again tyep cmd and do the below

:\> cd \my_mongo_dir\bin
C:\my_mongo_dir\bin> mongo

Reference

Upvotes: 1

qiao
qiao

Reputation: 18219

It seems that mongod is not running. Try to run mongod from your console

see http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo for full document

Upvotes: 0

Related Questions