Mongoose - remote database connect failed - node.js

I am trying to connect to my mongo database in my remote server:
$ mongo xxx.xxx.xxx.xx:27017
But I get this error:
MongoDB shell version: 2.6.10 connecting to: xxx.xxx.xxx.xx:27017/test
2016-11-07T05:18:39.140+0000 warning: Failed to connect to
xxx.xxx.xxx.xx:27017, reason: errno:111 Connection refused
2016-11-07T05:18:39.142+0000 Error: couldn't connect to server
xxx.xxx.xxx.xx:27017 (xxx.xxx.xxx.xx), connection attempt failed at
src/mongo/shell/mongo.js:148 exception: connect failed
Any ideas why?
I even have tried to connect it with an username and password but it still fails to connect...

Run this following command :
sudo service mongodb stop
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongod restart
mongo

Related

I can't connect to mongo db in ubuntu

MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
2018-10-01T17:38:22.425+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-10-01T17:38:22.426+0000 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
I get an error when I try to run mongo on the terminal.
I tried to reinstall and removed lock file and restarted it, but It still doesn't work. I am using AWS, is it some problem about inbound, outbound of network setting in AWS, Or any other problem?
Like the comments above, if you are trying to connect to a mongodb instance on the same host, using 127.0.0.1 it is a mongodb configuration problem, so, that is not possible to be any AWS Security Rules.
So, considering it is a mongodb problem, first try to repair it inside the host with:
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --repair
sudo service mongodb restart
sudo service mongod status
Refer: https://stackoverflow.com/a/29083477/8407784
After resolved the mongodb config problem, you need to test your connection from another host, setting /etc/mongod.conf - bind_ip = 0.0.0.0 (that means all interfaces), only for testing
Then you need to set your AWS Security Rules on the host instance allowing the external instance to access it on port 27017.

Unable run mongo shell in Ubuntu 16.04 after restart

I am unable to access mongo shell in Ubuntu 16.04, but am able to run
sudo mongod
and its working , but when i try to run
mongo or sudo mongo
the following error raises
MongoDB shell version v3.4.6
connecting to: mongodb://127.0.0.1:27017 2017-07-26T14:33:50.413+0000
W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking
socket for error after poll), reason: Connection refused
2017-07-26T14:33:50.414+0000 E QUERY [thread1] Error: couldn't
connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:237:13 #(connect):1:6
exception: connect failed
Print the last line of cat /var/log/mongodb/mongod.log and the content of /etc/mongod.conf.
Ensure that in /etc/mongod.conf the dbPath exists, the port is correctly bind to 27017, host is 127.0.0.1
In addition try to remove the mongod socket file /tmp/mongodb-27017.sock

How to run mongodb again after executing db.shutdownServer(); in the admin db

I was just learning mongodb. I command I entered are :
use admin
db.shutdownServer();
This shutdown the database. After that whenever I'm writing mongo to start mongoDB it gives me :
MongoDB shell version: 3.0.12 connecting to: test
2016-10-09T18:24:27.661+0530 W NETWORK Failed to connect to
127.0.0.1:27017, reason: errno:111 Connection refused 2016-10-09T18:24:27.664+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
When I run this : sudo service mongodb start
I get :
Redirecting to /bin/systemctl start mongodb.service Failed to start
mongodb.service: Unit mongodb.service failed to load: No such file or
directory.
I tried other different commands (even I've re installed it again) but none of them restarted mongodb.
How to start mongodb?
shut down the node
:SECONDARY> db.shutdownServer()
up
:~$ mongod --config /db/mongod-repl-2.conf
:SECONDARY> rs.slaveOk()
:SECONDARY> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
testDatabase 0.000GB
You need to fork your service again,
Try
mongod --dbpath /var/lib/mongo/ --fork --logpath /var/log/mongodb/mongod.log

mongo db can't start ubuntu 15.10

sudo service mongodb start
Failed to start mongodb.service: Unit mongodb.service is masked.
What should I do? help me..
~$ mongo MongoDB shell version: 3.2.3 connecting to: test
2016-02-26T17:40:18.552+0200 W NETWORK [thread1] Failed to connect to
127.0.0.1:27017, reason: errno:111 Connection refused 2016-02-26T17:40:18.552+0200 E QUERY [thread1] Error: couldn't
connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:224:14 #(connect):1:6
exception: connect failed
I think it's sudo service mongod start - please note the lack of b in mongod
I find the solution;
sudo mongod --dbpath /var/lib/mongodb/ --journal
different terminal is opening and
mongo
command is starting with

MongoDB connection failed, should I restart server or restart MongoDB

my computer is Ubuntu 14.04 LTS and I am connecting to a server to run codes. I also use the mongo on this server. However, it suddenly closed and when I tried to connect to the mongo shell, it shows:
MongoDB shell version: 2.6.9
connecting to: test
2015-05-02T16:37:34.643+0200 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-05-02T16:37:34.643+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
So should I restart mongo or should I restart the server? I use ps command to see all progresses on the server under my account, which is:
PID TTY TIME CMD
107018 pts/16 00:00:00 ps
233611 pts/16 00:00:00 bash
Does that mean that I cannot restart the server?
It seems mongodb suddenly shut down.
use sudo service mongodb restartto restart mongodb.
if it does not work and it is a test machine/personal computer ,
restart the machine is a good choice.
in addition,ps only shows your own process,sudo ps shows all process.

Resources