MongoDB Changing from localhost ip - mongodb

I'm trying to figure out how to run MongoDB, and am running into the follow error below:
How do I change my IP, do I change this in my mongod.conf? I'm running MongoDB on Virtualbox inside the virtual machine, running Ubuntu 14.04.
2015-01-19T01:02:38.625-0700 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-01-19T01:02:38.625-0700 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

These steps worked for me in getting MongoDB running and I didn't have to mess with changing any IP to match my VM:
1) edited /etc/mongodb.conf changed db-path=data/db
2) created data/db with the following:
sudo mkdir -p /data/db/
sudo chown id -u /data/db
3) ran mongod got an error with the following: Please make at least 3379MB available in /data/db/journal or use --smallfiles
4) re-ran with mongod --small files
5) opened another SSH window and ran mongo
6) mongodb loads - golden

Related

Unable to access mongodb running in a docker from local machine

I am trying to access the mongodb running in a docker from my local machine however I am seeing this error message:
Error: couldnt connect to server localhost:27017, connection attempt failed: SocketException: Error connecting to localhost:27017 (127.0.0.1:27017) :: caused by :: No connection could be made because the target machine actively refused it.
commands tried to used to access mongo on my local machine:
mongo localhost:27017
mongo 172.17.0.2:27017(container's ip)
command used to run mongodb on docker
docker run -d -p 27017:27017 mongo:latest
Please advice. Thank you.

Running `mongo` in the command line is giving error

I am trying to start a MERN app, I have installed mongo and any relevant things. But when I run mongo in my terminal the following appears.
I have looked across the board but the solutions do not help me. I am also running on Ubuntu 20.04.
MongoDB shell version v4.4.3
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:374:17
#(connect):2:6
exception: connect failed
exiting with code 1
Fixed the issue by running
$ sudo rm -rf /tmp/mongodb-27017.sock
$ sudo service mongod start
Try to start the MongoDB server first running mongod command or from task manager>services> MongoDB server> right-click and start it
Read this Document for more

Mongodb connection error whenever rebooting server

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

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