GCE VM instance reset and unable to connect to MongoDB - mongodb

Failure to connect to mongodb after VM instance is reset.I get the following error
"Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused"
tried the following, but did not work
$ sudo service mongodb start
$ sudo mongod --repair

It seems like your MongoDB service is not set to to start automatically on server's reboot. You will need to either reinstall the mongodb or set the service to start on reboot by using sudo systemctl enable mongodb

Related

Could not run MongoDB server in Ubuntu system

I am trying to run MongoDB in my Ubuntu machine using the following command but I am getting some error.
Command:
mongo
Error:
connecting to: mongodb://127.0.0.1:27017<br>
2019-12-23T17:00:38.815+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused<br>
2019-12-23T17:00:38.818+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :<br>
connect#src/mongo/shell/mongo.js:251:13<br>
#(connect):1:6<br>
exception: connect failed
How can I resolve this issue and run MongoDB successfully?
Normally this is caused because you didn't start mongodb service before you try starting mongo shell. You can check for a system service status. If it is failing because of some error try to fix it and start the process. Below are few things that might help with it.
Check if mongodb service is up and running
sudo systemctl status mongodb
If not start mongodb service on your ubuntu machine
sudo systemctl start mongodb
Start mongo shell
mongo

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 :-)

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

can't run mongo as a service

So I've got a virtual machine running on windows azure and installed mongoDB. However mongod works fine when I do: mongod --dbpath /mnt/datadrive/data but when I end the process and do mongo, I get:
2015-01-10T14:23:17.474+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-01-10T14:23:17.476+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
I've edited the config /etc/mongod.config however when I try and run sudo service mongo start I get:
Job for mongod.service failed. See 'systemctl status mongod.service' and 'journalctl -xn' for details.
What I'm initially trying to do is have mongoDB running as a service on my virtual machine so I can remotely can connect to it at anytime.
When you typed in the mongod command, did you also give it a path? This is usually the issue. You don't have to bother with the conf file. simply type
mongod --dbpath="put your path to where you want it to save the working area for your database here!! without these silly quotations marks I may also add!"
example: mongod --dbpath=C:/Users/Kyle-3/Desktop/DEV/dangerzonearea/test/mongodb
That is my path and don't forget if on windows to flip the slashes forward if you copied it from the or it won't work!
Solution:
Don't end the service. Let it continue while you use mongo from another cmd or shell.

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.