0

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!

Vegeta
  • 1
  • Possible duplicate of [Is mongodb running?](https://stackoverflow.com/questions/5091624/is-mongodb-running) – Tilo Jun 03 '18 at 17:57

2 Answers2

0

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

Documentation

X.Otano
  • 2,079
  • 1
  • 22
  • 40
0
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
Anton Belousov
  • 1,140
  • 15
  • 34
Ishan Garg
  • 571
  • 5
  • 13