6

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
JohnnyHK
  • 305,182
  • 66
  • 621
  • 471
Huy Tran
  • 4,371
  • 10
  • 34
  • 38

9 Answers9

7

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)

Community
  • 1
  • 1
alessioalex
  • 62,577
  • 16
  • 155
  • 122
  • 1
    yesterday,mongo ran but today it doesn't run... i checked folder `/data/db`, it's installed... So, what do i do to run my `mongo`. – Huy Tran Jan 04 '12 at 03:36
  • could u give me an example app about use express and mongoose to login..? thank you so much. – Huy Tran Jan 04 '12 at 03:53
  • @EnzoTran http://stackoverflow.com/questions/8397977/how-to-do-authentication-with-node-js-express-and-mongoose – alessioalex Jan 04 '12 at 07:21
  • thank so much.. i'm really happy when receive your enthusiastic help from you. could you give me your skype to contact to get easier. It's my skype: `tranhoanghuy0905`. – Huy Tran Jan 04 '12 at 07:32
6

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

bitmill
  • 83
  • 1
  • 5
2

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

C:\> mkdir \data
C:\> mkdir \data\db
Andy Petrella
  • 4,345
  • 26
  • 29
  • Great... if it was the proble, don't forget to accept the solution... so that other will be warned to not forget this mandatory step. Which from my POV, MUST have a dedicated error code, or at least meaningful error message – Andy Petrella Jan 03 '12 at 14:37
1

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

Melsi
  • 1,462
  • 1
  • 15
  • 21
1

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

xkeshav
  • 53,360
  • 44
  • 177
  • 245
0

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/

0

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

Dickens
  • 35
  • 5
0

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

qiao
  • 17,941
  • 6
  • 57
  • 46
-1

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.
Doris Hernandez
  • 129
  • 1
  • 3