connect failed mongo db on mac osx

Viewed 21826

i'm trying to learn mongo db on my mac. I installed mondgo db using homebrew and it appeard successful. I created the dir /data/db. when I type mongo into the terminal I get:

Error: couldn't connect to server [a bunch of numbers] at src/mongo/shell/mongo.js:145 exception:connect failed

I looked at the following answer on SO: Installing and Running MongoDB on OSX

in the check answer it says: 1) Start a terminal for your mongo server 2)Go to mongo/bin directory

What does it mean to start a terminal for your server? does that mean just open up a new terminal window?

Where can I find the mongo/bin directory?

Any other suggestions on getting mondoDB up and running would be appreciated.

4 Answers

you should read the documentation here: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/ And follow the instructions.

In this case the [bunch of numbers] are the hostname/ip and port number that the binary mongo has tried to connect to. What it's telling you is that there is no mongod binary listening on the hostname and port that mongo is trying to connect to.

You will need to start mongod before you are able to connect to it with a mongo shell. The documentation above outlines this further.

If you use homebrew the mongodb binaries will automatically be put on your path which means you won't need to cd into another directory like mongo/bin.

Good luck.

when everything mentioned above did not work. I did the following thing (in Mac)

cd ~
mkdir -p data/db

After creating directory in home(which will be definitely allowed) most imp command is below

mongod --dbpath ~/data/db &

So that it could take the path of db which was in home directory (as we are not able to create in / dir. To avoid it running frequently, put the above command in .bash_profile file in home directory so that it will automatically run the above command whenever we try to use terminal in Mac

Note: Whenever we open the terminal it will execute the above command so that we can access the mongodb (I understand this should be taken place in background but it works fine) We need to press enter/return key to get the regular command line terminal and continue doing our work

Related