Can not connect MongoDB docker-compose - mongodb

Can not connect mongodb run in docker-compose
MONGO_URL=mongodb://db:27017/500ae_cms
error:
MongoDB connection error: mongodb://db:27017/500ae_cms.
MongoNetworkError: failed to connect to server [db:27017] on first connect [Error: getaddrinfo ENOTFOUND db
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26) {
name: 'MongoNetworkError',
errorLabels: [Array],
}]
docker-compose file

For your db service you expose port 27775 but in your app you try to connect to 27017.
Docker resolves the service name in an IP address but this fails here (too?)
failed to connect to server [db:27017];;; getaddrinfo ENOTFOUND db
should at least be something like:
failed to connect to server [db:27017] on first connect [Error: connect ECONNREFUSED 17.19.0.2:27017

Can you try running nslookup db from the api container? If that resolves, then it might be an issue with your mongo driver.

Related

Mongo failed to start

I am running a mean app, but when I go to run 'mongo', I get the following error:
MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
2018-07-25T02:15:24.329-0500 E QUERY [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 :: Connection refused :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
I am sure I am missing something simple here.
mongo is the Mongo shell. It connects to the Mongo daemon, mongod, which isn't running - hence the error.
At the command-line: sudo mongod
Enter your password, and the daemon should start. Now, when you run mongo it should start up ok.

Failing to connect to mongodb

I've been told by my professor to use linux to install nodejs, expressjs, and mongoDB. I've installed mongodb from the terminal, but when I try to execute the command "mongo", I get this:
MongoDB shell version: 2.6.10
connecting to: test
2018-01-20T11:58:05.602-0500 warning: Failed to connect to
127.0.0.1:27017, reason: errno:111 Connection refused
2018-01-20T11:57:05.603-0500 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

How to connect to MongoDB

I am conecting mongo db everyday ,it worked fine but today it troubled me with the below error,can anyone help me please.
MongoDB shell version: 2.6.10
connecting to: test
2017-01-10T14:26:13.073+0530 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2017-01-10T14:26:13.074+0530 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
Run the following command
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongod restart

MongoDB MongoDB connection error: MongoError: connect ECONNREFUSED 127.0.0.1:27017 error when my router is turn off

whenever my router goes off ... my mongod connection dont work . I had power cut twice and found this error while starting my application. Once my router was up I was able to reconnect mongo db
MongoDB connection error: MongoError: connect ECONNREFUSED 127.0.0.1:27017 while wifi router is off.
Have you tried to change the mongo-connection?
Change your connection string from localhost to ip:
mongodb://localhost/test to mongodb://127.0.0.1:‌​27017/test

Whats wrong with my Mongo query?

I've recently set a path in my vi .bash_profile to my mongo commands. I know this works because it was working yesterday.
However when I do it now I get this error:
AMAC02MX3APF8J3:~ james.flan$ mongo
MongoDB shell version: 3.0.3
connecting to: test
2015-05-19T11:34:58.708+0100 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
2015-05-19T11:34:58.710+0100 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
Here is the content in my vi .bash_profile:
alias mongod="mongod --dbpath /Users/ryan.garrett/Documents/Software/MongoDB/data"
export PATH="/Users/ryan.garrett/Documents/Software/MongoDB/bin:$PATH"
Can someone please tell me how to connect to the server?
Check your /etc/hosts for localhost entry and also make sure that mongod is listening to all interfaces, you can check by netstat -an|grep mongo.