Vegeta
Vegeta

Reputation: 1

Mongodb problem_could not connect to server

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!

Upvotes: 0

Views: 336

Answers (2)

Ishan Garg
Ishan Garg

Reputation: 629

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

Upvotes: 0

X.Otano
X.Otano

Reputation: 2169

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

Documentation

Upvotes: 0

Related Questions