Error connecting to Mongo Atlas - node.js

I am working on a nodejs project and using mongoose module I want to connect to Mongo Atlas,
I used
mongoose.connect('mongodb+srv://<USER>:<PASSWORD>#varcv-okhmh.mongodb.net/<DATABAS_NAME>?retryWrites=true');
but I got an error:
failed to connect to server [varcv-shard-00-00-okhmh.mongodb.net:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 35.158.192.211:27017]
I also try to connect via old connection string
mongoose.connect('mongodb://peter:<PASSWORD>#varcv-shard-00-00-okhmh.mongodb.net:27017,varcv-shard-00-01-okhmh.mongodb.net:27017,varcv-shard-00-02-okhmh.mongodb.net:27017/<DATABAS_NAME>?ssl=true&replicaSet=varcv-shard-0&authSource=admin&retryWrites=true');
But I got the same error.
Notes:
everything is working perfectly on my local machine the error is happens when I upload my code to Godaddy Linux Shared hosting.
I am using PM2 to run my server.
I am using Mongo 3.6.5
I am using mongoose 5.1.5

Related

Depending on HOST NAME value for PostgreSQL database in my .env file I get different result

I have created a PostgreSQL with a web server DOCKER CONTAINER and my app running with an API to manage all the endpoints.
The link of my git repo is: https://github.com/JulioValderrama/store-front-project.git
But I am facing problems with the connections with the Database, as depending on the Postgres HOST name value in my .env file one of the two servers (one local running in PORT 4000 and the web server running in the docker container in PORT 3000) will work or will fail.
I have tried the next:
Local server running in PORT 4000
Docker web server running in PORT 3000
HOST "127.0.0.1"
Going to¨:
http://localhost:3000/
Works fine and get response, now when trying to connect it to any of my database API:
http://localhost:3000/products
I get the error:
"Could not get PRODUCTS. Error: Error: connect ECONNREFUSED 127.0.0.1:5432"
Going to:
http://localhost:4000
Works fine and get response, now when trying to connect it to any of my database API:
http://localhost:4000/products
It works! I get the list of all my products!!
HOST "postgres"
I put "postgres" because I read online that you have to name HOST as the postgres docker image created, which is my case. And it works for the remote server.
Going to:
http://localhost:3000
Works fine and get response, then when trying to connect it to database API:
http://localhost:3000/products
It works!! It gives me the list of my products !!
Going to:
http://localhost:4000
Works fine and get response, then when trying to connect it to database API:
http://localhost:4000/products
It gives me the error:
"Could not get PRODUCTS. Error: Error: getaddrinfo ENOTFOUND postgres"
So it seems like there is an error when trying to connect to the database due to the server or the HOST name, I have no idea....
In docker-compose.yaml you have linked your machine 5432 to containers 5432 port.
If you are using docker container and want to reach postgres, use postgres as POSTGRES_HOST value.
If you are running application outside the docker environment use 0.0.0.0, 127.0.0.1.
Make sure you haven't installed postgres locally
brew uninstall postgres

can not connect to postgres db from node server

I want to connect my apps nodejs using node-posgres to PostgreSQL. My apps in linux server and my postgresql in another linux server by 176.9.154.123 IP.
this is my error:
this is my pg_hba.conf:
host all all 176.9.154.123/32 trust
i can solve this problem by add this line to postgressql.conf:
listen_addresses = '*'

Mongodb crud with an ionic application

I created a database on a remote server. I created a js file to connect to the database using mongoose, express, body-parser.
I made a connection to the remote server with the following command:
mongoose.connect ("mongodb: //176.31.212.51: 27017 / db")
I test the connection and I have a successful connection,
I launched a "listener" to listen on the port as follows:
app.listen (process.env.PORT)
with the port = 3000
I tested and I got an error.
Is there any solution to make a successful connection with the ionic application to do the operations of CRUD?

MongoDB: No unix socket support on windows

I use Robo 3T as a UI tool for MongoDB on a Windows 8 machine. Now I've deployed the DB to production on a Ubuntu 14 server in Amazon EC2 cloud. When I try to connect from the Windows machine to the Ubuntu one via Robo 3T, I receive the following error:
Cannot connect to the MongoDB at [http://12.345.678.90]:27017.
Error: No unix socket support on windows
Is that a problem I need to fix on my computer by installing something? or it's an issue of Mongo 3T?
If it's an issue on my Windows, what do I have to install in order to make it work?
If it's a Mongo 3T issue, do you know another UI that does support connecting from Windows to Ubuntu?
Perhaps an EC2 solution?
Or maybe some settings I need to change in Robo 3T?
I've tried changing "http" to "mongodb" to no avail. I've also tried removing the protocol prefix as suggested here but I ended up with the error:
Cannot connect to the MongoDB at 12.345.678.90:27017.
Error: Network is unreachable.
Do you have a bindIP setting in your mongo configuration file? Probably that can cause the error.
Either remove the bindIp configuration or allow your IP to access mongo server.
(restart your service after changes the configuration).

Why is my nodejs express server connecting to the MongoDB on my local machine and the AWS EC2 Instance

I have a MongoDB running on my local machine and another MongoDB running on the AWS EC2 instance where my express server and my angularjs web app is installed. That is:
On my local machine (Windows environment), running:
MongoDB
Nodejs Express server
On AWS EC2 instance (ubuntu), running:
MongoDB
Nodejs Express server
AngularJS web app
When I browse my web side running on AWS EC2 instance (using https://ec2_public_ip:3443/home/app/index.html), it retrieves data from the MongoDB running on my local machine. If I shut down the MongoDB and Express server on my local machine, I get Failed to connect to resource error. Why is my express server not connecting to the MongoDB running on AWS?
This is my connection string in the app.js file:
'mongoUrl' : 'mongodb://localhost:27017/myMongodatabase',
I also tried
'mongoUrl' : 'mongodb://0.0.0.0:27017/myMongodatabase',
Both did not work on my AWS instance.
I'm learning to use MongoDB, AWS, Express and now I am confused. Any help is appreciated.

Resources