Mongo DB is started, but it doesn't work - mongodb

I have 2 servers: One Ubuntu Server and a debian Server. I've installed Mongo DB and mongod will start, but when I try the command "mongo", I get the follow message:
MongoDB shell version: 2.4.9
connecting to: test
Tue Jun 28 19:01:21.922 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
I start the MongoDB with this command:
clouduser#caridio-ubuntu-2:~$ sudo service mongodb start
sudo: unable to resolve host caridio-ubuntu-2
mongodb start/running, process 18555
I tried to set an other dbpath and to install an older version of MongoDB. I set up differnt servers. MQTT and Tomcat works both.
Here my config:

it's an answer from 2 years ago
bindIP = [127.0.0.1,141.28.102.148]
so try to add your ips inside the [ ]
if you don't have others interface you can use bindIP = 0.0.0.0
source https://stackoverflow.com/a/34698336/6523542
maybe duplicate of ?? mongodb.conf bind_ip = 127.0.0.1 does not work but 0.0.0.0 works

Related

Not able to connect to mongodb database

Every time if my server restarts by mistake or I stopped and then restart I'm not be able to connect to my mongodb. I get this below error and according to this 27017 port is not open but in my security group I opened this port.
MongoDB shell version v5.0.2
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:372:17
#(connect):2:6
exception: connect failed
exiting with code 1```
So, I don't know what I'm doing wrong please help me because I'm facing this issue from very long time and to rid of this I've to always setup new mongodb
You need to define the MongoDB as service and set to automatic start.
On Windows add lines similar to
processManagement:
windowsService:
serviceName: mongod
displayName: MongoDB
description: MongoDB Server
to your configuration file (typically mongod.conf or mongod.cfg), if not already existing.
Then the easiest way to install the service is running
mongod.exe --config <your config file> --install
On Linux (Redhat, Centos, etc.) it works like this.
Copy default service file
/usr/lib/systemd/system/mongod.service to /etc/systemd/system/mongod.service
Customize service file /etc/systemd/system/mongod.service, if needed
Enable the service: systemctl enable mongod
Start the service: systemctl start mongod

Unable to connect specific mongo instance port

Today morning i'm able to create 2 different mongo instances on port 27010 and 37010 and i'm able to replicate using mongo-connector. But now after system restart i'm not able to connect to port 37010 using below command.
C:\Program Files\MongoDB 2.6 Standard\bin>mongo --port 37010
MongoDB shell version: 2.6.12
connecting to: 127.0.0.1:37010/test
2016-09-12T18:08:14.733-0500 warning: Failed to connect to 127.0.0.1:37010, reason: errno:10061 No connection could be made because the target machine actively refused it.
2016-09-12T18:08:14.756-0500 Error: couldn't connect to server 127.0.0.1:37010 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:148
exception: connect failed
It is working fine if i just give mongo where it is connecting only to default port of 27010. Morning also i faced same problem where i deleted all my mongo windows service and running without mongo windows service. But again i'm facing same problem. Kindly advise.
Below is my config files.
mongo.config.txt
##store data here
dbpath=C:\Program Files\MongoDB 2.6 Standard\data
##all output go here
logpath=C:\Program Files\MongoDB 2.6 Standard\log\mongo.log
logappend=true
#port number
port=27017
##log read and write operations
diaglog=3
#replica set name
replSet=rs1
# only run on localhost for development
bind_ip = 127.0.0.1
mongo2.config.txt
##store data here
dbpath=C:\Program Files\MongoDB 2.6 Standard\data2
##all output go here
logpath=C:\Program Files\MongoDB 2.6 Standard\log2\mongo.log
logappend=true
#port number
port=37017
##log read and write operations
diaglog=3
#replica set name
replSet=rs2
# only run on localhost for development
bind_ip = 127.0.0.1
I got answer to my problem by following the steps mentioned in below blog.
http://zdk.github.io/create-a-three-member-mongodb-replica-set
Somehow it didn't work for me with configuration file. But I resolved my problem by executing commands in command line .

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

Mongo Shell couldn't connect to the local server

I'm starting MongoDB using the following command:
sumeet#sumeet-acer:~$ sudo service mongod start
I get a reply as:
mongod start/running, process 7209
sumeet#sumeet-acer:~$
But when I try to enter MongoDB shell by typing mongo I get the following error:
sumeet#sumeet-acer:~$ mongo
MongoDB shell version: 2.0.4
connecting to: test
Fri Jun 12 14:01:59 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
By default, mongod and mongos use the 27017 port. Without any option, the client will try to connect to a server running on localhost and listening at that port.
A few general advices here:
check if the mongod server is really running (ps -edf | grep mongod);
check if it uses the default port (look in the config file1, or use nmap localhost -p0-65535 or netstat | grep 27017);
if mongod is not running, check in the log2 for clues about what goes wrong.
1 /etc/mongodb.conf (on Debian-like systems at least)
2 /var/log/mongodb (on Debian-like systems at least)
The default IP and Port for MongoDB is 127.0.0.1 & 27017.
If you are using config file for specifying settings than re-verify IP & Port mentioned in it.
If you are going with default option than mongod should function as expected.
try mongo 127.0.0.1:27017
this worked for me
For MongoDB 2.2.2 running on Ubuntu 12.10, it's in /var/lib/mongodb/mongod.lock
and after that running the repair command
sudo -u mongodb mongod --repair --dbpath /var/lib/mongodb/
courtesy: https://stackoverflow.com/a/13700262/4907105

Cannot connect to mongod running in Ubuntu machine

I would like to connect with mongo from a cmd shell in windows to a mongod database running in a Ubuntu virtual machine.
mongo is running fine in the Ubuntu terminal and from a putty shell
When I use mongo from a windows cmd shell, I got this error:
mongo.exe --host 192.168.1.6 --port 27017
MongoDB shell version: 2.4.6
connecting to: 192.168.1.6:27017/test
Sat Feb 01 14:45:32.181 Error: couldn't connect to server 192.168.1.6:27017 at src/mongo/shell/mongo.js:147
exception: connect failed
What should I do to be able to connect?
My goal is to use MongoVue to connect to the mongod database in the Ubuntu machine (by the way, MongoVue is not connecting even using its SSH options).
I am trying to connect to the mongod instance of a meteorjs application.
The meteor application is up and running and I can connect to the mongod instance running on the Ubuntu machine at port 3002, both in the Ubuntu terminal and with a putty shell.
stefano#MeteorDeploy:~$ mongo --port 3002
MongoDB shell version: 2.0.4
connecting to: 127.0.0.1:3002/test
PRIMARY> show dbs
local 0.0625GB
meteor 0.0625GB
I would like to connect to the mongod instance using MongoVue as alternative of the putty shell.
I did as in the docs.mongodb.org/manual/tutorial/configure-linux-iptables-firewall/ but without success.
Meteor runs it's own instance of mongo per app. As you note since your edit, when you ssh into your VM you use --port 3002 to connect.
Now you could add that port to your mongo shell launch except for one problem
ps -ef | grep mongo
on your VM will show you the running instance of mongo along with it's startup options. By default this will be bound to 127.0.0.1 which is the loopback adaptor and not accessible outside of the VM.
So what you need to do is either change the startup options in your project, or use another instance on mongo installed on the local machine.
export MONGO_URL=mongodb://localhost:27017/your_db
By default mongod insllation on Ubuntu only listen to localhost, so you can't connect from Windows.
Edit /etc/mongodb.conf and change the bind_ip line (add your windows IP adress on the local network) so it will accept connection.
Be aware that by default mongod does not require authentification so you would maybe want to settup one.
Doc is here :
http://docs.mongodb.org/manual/reference/configuration-options/#bind_ip
For quick and dirty solution (not for Production):
Edit /etc/mongodb.conf and change the bind_ip to 0.0.0.0