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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With