0
votes

I use ubuntu 14.04LTS and with mongodb version 2.4.9.When I type "mongo" in terminal, it always show "connecting to: test Tue Jun 3 10:03:57.911 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145 exception: connect failed". But if i run mongod in one terminal, and run mongo in another, all is ok. If I close the window of mongod, the connection fail again. I need to use mongodb without open a terminal of mongod, how can I do with it ? Thank you!

2
Possible duplicate of Is mongodb running?Tilo

2 Answers

0
votes

You need to start mongodb as a service or daemon(depending on the OS,in your case daemon), check the documentation

Documentation

0
votes
sudo service mongod start

Or

To run a mongod process as a daemon (i.e. fork), and write its output to a log file, use the --fork and --logpath options. You must create the log directory; however, mongod will create the log file if it does not exist.

The following command starts mongod as a daemon and records log output to /var/log/mongodb.log.

mongod --fork --logpath /var/log/mongodb.log