Mongodb connection error whenever rebooting server - mongodb

I am using aws and installed ubuntu server on aws ec2.
I installed mongodb on it.
When installing mongodb, it is working well.
But If i reboot server and try to connect mongod in termina. I am getting the following error.
MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:362:17
#(connect):2:6
exception: connect failed
exiting with code 1
So whenever reboot server, i have to execute the following command and then mongo is working again.
sudo systemctl stop mongod
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair --dbpath /var/lib/mongodb
sudo mongod --fork --logpath /var/lib/mongodb/mongodb.log --dbpath /var/lib/mongodb
sudo systemctl start mongod
I think whenever reboot server, executing above command does not make sense.
If anyone have experienced, please help me.
Thanks.

After you setup the mongodb you usually would enable it, so that it starts after each reboot:
sudo systemctl enable mongod

Related

MongoDB, NodeJs. No connection could be made because the target machine actively refused it. :

I am trying to connect to my MongoDB database in localhost. While I type mongo in command shell I am getting an error in the command shell:
js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: No connection could be made because the target machine actively refused it. :
connect#src/mongo/shell/mongo.js:341:17
This will start the mongo server as a service:
brew services start mongodb-community
command mongod will run the MongoDB server using the default configuration. You can change these configurations by locating the default path of the configuration files.
The primary daemon process for the MongoDB database system is called mongod. You need to start this service before making connection attempts.
You can do this in Ubuntu by:
sudo service mongod start
or,
sudo systemctl start mongod
Start mongod on system boot by:
systemctl enable mongodb.service
I had the same issue.
When running mongod command, it mentioned the C:/data/db as E:/data/db path.
After I created the folder in mentioned E:/data/db path it works!
For windows user
1. Type ctrl + r
2. Scroll to mongodb server
3. start the server
do you have a linux distro? If you do, the solution is a bit annoying as you have to do it everytime you start your pc. The solution is:
Type "mongo" and "mongod" once in the terminal. It will show an error, don't worry, that's the whole point
type this:
chown -R mongodb:mongodb /var/lib/mongodb
chown mongodb:mongodb /tmp/mongodb-27017.sock
sudo service mongod restart
tip: copy the whole thing and paste on the terminal using ctrl+shift+v. You're welcome :-)

mongodb error. how can I solve the erro in mongoDB?

MongoDB shell version: 3.2.6
connecting to: test
2016-05-08T10:46:12.023+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-05-08T10:46:12.023+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:229:14
#(connect):1:6
exception: connect failed
https://docs.mongodb.com/v3.0/tutorial/install-mongodb-on-ubuntu/
Do you have the mongodb service running? Run sudo service mongod status and see what it returns. If it is stopped, run sudo service mongod start to start the mongodb and try connecting to it.
You can also, check whether the mongodb is listening on 27017 or not by running: sudo netstat -lnp | grep 27017.
If sudo service mongod start is giving a error, you may need to check the configuration. We can help you better if you can post the output of the above commands.
Update:
Create the file /etc/systemd/system/mongod.service with the following content:
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
Just restart the service in terminal, verbose mode helps you to understand the background configuration
$brew services restart mongodb --verbose
and open another terminal (don't use same terminal) and type mongod, you should be able to see process running.
Excuse have the same problem . Just installed Ubuntu 16.04 LTS . The installation process , the same as in the official website of mongo . When I do:
sudo service mongod status; appear
● mongod.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
I guess the error will be in the configuration of "data directory" and the port, but not as configure it properly
Fork your mongodb process as a daemon so that it keeps running in background. E.g
./mongod --port 27017 --dbpath /home/db_directory --logpath /logs/mongod.log --fork

Already running Mongo db start up issue in ubuntu

I have issue with Mongo DB start up in ubuntu 14.04 64 bit,its working fine when i installed first time but suddenly from now when i type mongo in ubuntu terminal its showing error:
MongoDB shell version: 3.0.7
connecting to: test
2015-11-26T11:59:03.888+0530 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-11-26T11:59:03.889+0530 E QUERY Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:179:14)
at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed
I tried many solution
i.e
1.deleting lock files, and restart mongo,
2.Change bind ip to 0.0.0.0 in mongod.conf
but my issue still not resolved.
Try to execute the following command to grep process id of mongod to determine if mongo service is running or not
pgrep mongod
If process id exists then please follow the steps as mentioned below
(a) Kill existing mongod process using following command
sudo kill -9 [process_id]
(b) Start mongod process using
sudo mongod --noauth --dbpath /var/lib/mongodb

I couldn't MongoDB Installation on Debian

I installed mongodb from this link
When i entermongo in console I got error
root#512son:~# mongo
MongoDB shell version: 2.6.9
connecting to: test
2015-04-10T05:35:23.837+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-04-10T05:35:23.838+0000 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
I searched this problem on internet and i tried:
sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
If i enter mongod in terminal Mongodb work fine but when i close terminal mongodb is closing
I reinstall two times but my problem not fixed
You need to run MongoDB in the background. I mean start mongod as daemon using --fork

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.