Failed to restart mongod.service: Unit mongod.service not found - mongodb

While restart mongodb server using below command. its showing error like : Failed to restart mongod.service: Unit mongod.service not found.
sudo service mongod restart

sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongodb start

You can try
sudo systemctl unmask mongodb
and re-run
sudo service mongod start

Related

Cannot run mongod.service and therefore cannot connect to mongo

I accidentally killed my mongo local server, so every time I want to connect I have to run this command:
mongod --port 27017 --dbpath /var/lib/mongodb --logpath /var/log/mongod.log
How can I run it automatically?
I'm missing for some reason the mongod.service file, so I cannot run systemctl start mongod.
If anyone can please provide a solution (or the missing file) it will be helpful.
If you run this, I think the service will be modified and restored.
sudo systemctl enable mongod
Then run it again.
sudo service mongod restart

Mongod [initandlisten] dbexit: rc: 48

When I run mongod I recieved this error. How can I solve this? Thanks.
enter image description here
Try to stop current active mongodb service and run it again
$ sudo service mongod stop
$ mongod
You may encounter the problem of Failed to stop mongod.service: Unit mongod.service not loaded, this error says that your mongod is not running. Check this answer
If you use Mac
$ sudo killall mongod
If it did not work, try to find out which process is running on port (27017) and kill it
$ sudo netstat -tulpn | grep :27017
Kill the process
$ sudo kill <pid>
Or just try on another port with mongod --port 27027

Install mongodb on ubuntu with apt-get fails

I'm trying to install mongoDB on Ubuntu Server 14.04 with apt-get.
My command ist sudo apt-get install mongodb-org -y
After installation I'm trying to run sudo service mongod start
The output is mongod start/running, process 11977
Trying to get status sudo service mongod status prints out mongod stop/waiting
Trying to stop mongod sudo service mongod stop prints stop: Unknown instance:
When I type mongo in command line I get this
MongoDB shell version: 2.6.3
connecting to: test
2014-08-02T11:49:28.781+0200 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-08-02T11:49:28.782+0200 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
What I'm doing wrong?
mongod is not running, thats why you cant connect. Before you run it as a service, just run mongod from the command line and see how it fails. Once you get it working, you can convert to a service.

mongo is not connecting but installed and show version

i have following step.
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
sudo gedit /etc/apt/sources.list
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
sudo apt-get install mongodb-10gen
when i run command
mongo --version
result was
MongoDB shell version: 2.4.9
then at command
sudo start mongodb
result
mongodb start/running, process 5808
at command
sudo stop mongodb
result was
stop: Unknown instance:
at command
mongo
result was .MongoDB shell version: 2.4.9
connecting to: test
Sun Mar 2 18:57:50.050 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
again on command
sudo service mongodb restart
stop: Unknown instance:
mongodb start/running, process 5873
mongo
MongoDB shell version: 2.4.9
connecting to: test
Sun Mar 2 18:57:50.050 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
Did you try to remove .lock file from /var/lib/mongodb/ ?
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongodb restart
Also you can try: sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/ and then start mongo again.
Hope this helps

MongoDB Error couldn't connect to server

I first execute the command:
sudo service mongodb restart
I get the prompt:
stop: Unknown instance:
mongodb start/running, process 3175
Then,I execute the command:
mongo
I get the error:
MongoDB shell version: 2.4.6
connecting to: test
Tue Oct 8 19:48:08.961 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
I don't know how I get this error.
Execute the following command
sudo rm -rf /var/lib/mongodb/mongod.lock
then
sudo service mongodb restart
Just Execute these following lines:
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo start mongodb
sudo status mongodb
mongo
Now you can access to your mongo terminal.