Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 816
Huy Tran Avatar asked Jan 03 '12 10:01

Huy Tran


People also ask

Why is my MongoDB not connecting?

If you have created a user and are having trouble authenticating, try the following: Check that you are using the correct username and password for your database user, and that you are connecting to the correct database deployment. Check that you are specifying the correct authSource database in your connection string.

How do I connect to a MongoDB connection?

To connect to a MongoDB Server using username and password, you have to use 'username@hostname/dbname'. Where username is the username, password is the password for that user and dbname is the database to which you want to connect to. Note : You can use multiple hostname to connect to with a single command.

Why does MongoDB say Connection Refused?

In short, the top most causes of this error Mongodb connection refused in Ubuntu are conflicting rules in the server firewall for the MongoDB port or bad settings in mongod. conf file.

Is MongoDB down right now?

MongoDB Cloud Status is Operational.


4 Answers

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

C:\> mkdir \data
C:\> mkdir \data\db
like image 45
Andy Petrella Avatar answered Nov 10 '22 01:11

Andy Petrella


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)

like image 148
alessioalex Avatar answered Nov 09 '22 23:11

alessioalex


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

like image 26
bitmill Avatar answered Nov 10 '22 01:11

bitmill


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

like image 34
diEcho Avatar answered Nov 10 '22 00:11

diEcho