queryTxt ETIMEOUT merncluster-0jdze.mongodb.net - node.js

I'm using nodejs with MongoDB server using mongoose, whenever I try to run my server, it won't connect to my database. After sometime above log is seen on CMD. My cluster name is merncluster here!!
Is there any solution to this, I've searched a lot, still can't find proper solution to this, this keeps happening all the time.

You may need to whitelist your IP address in MongoDB Atlas.

Adding 8.8.8.8 to my connection to the internet works for me.

Related

Unable to connect ECONNREFUSED / Unable to connect ENOTFOUND mongo db vsCode

I'm trying to connect my mongodb to my vscode and when I try and connect to it using 'mongodb:// it comes up with a connection error. Can anyone help me with this please? 1
you need to try this flow to solve your issue. might be it helps you.
check mongo service is running or not.
if you mongo service is out side of your current machine than you check your IP has access to access your mongo service
check your mongo connection URL is correct.
try to connect your MongoDB using tools like MongoCompass or Robo 3t.
then try in your code for further task

Router cannot connect to MongoDB cluster

I am working on a MERN project. I was previously able to connect to the MongoDB cluster via the connection string in my node application. A few days ago I changed my wifi router and I am not able to connect to the database anymore.
I am sure the problem is the router because when I connect through my phone's internet, the connection is successful. Unfortunately, I cannot use my phone's internet always as it is really expensive.
I have tried to factory reset my router as suggested in this question.
Error at connecting to MongoDb Atlas Server
I have also tried to enable port forwarding for port 27017, 27018, 27019 (default ports of MongoDB) through the router settings as suggested by someone on the internet.
Screenshot of my router settings
But did not face any success.
Some additional information. I am using a d-link router(DIR-819). The latest version of windows, node.js at the time of asking this question. Any help would be greatly appreciated as I am stuck on this problem for hours now.
EDIT: Here is the output when I try connecting through the shell.
DNSHostNotFound: Failed to lookup service ": This operation returned because the timeout period expired.
try 'mongo --help' for more information.
Please help me out, guys.
I have whitelisted all the IP addresses.
Cheers Everyone
Okay, look I'm also facing the same issue.
The reason behind this is because your Router is not letting your backend to make a connection with the MongoDB atlas.
You can still use it through your mobile network. Connect your PC with your mobile network and then try again it will work. (worked for me)
And for the Router issue, I'm still searching the solution once I find it, I'll be updating the answer. And yes if you find the solution before me be sure to Update us.
Use MongoDB in local machine. If that helps. I was also facing a similar issue so dropped the idea of connecting it to MongoDB Atlas. I downloaded it and it's running smoothly
Try to downgrade nodejs driver. I have resolved this by downgrading nodejs 3.2 driver string to 2.2 driver string.

Alternatives for connecting MongoDB Atlas to Heroku Node.js app

I've been working on a simple website using node.js, express, and MongoDB, with Heroku as the platform. I had a lot of issues early on trying to connect to my MongoDB Atlas cluster, resulting in Heroku throwing request timeout errors.
After some googling, I surmised that the issue was that the IP addresses Heroku sends requests to my DB from weren't whitelisted in Atlas. The simplest solution at that point was to egregiously set up so that any IP is considered whitelisted. Which actually works fine currently.
My actual question comes down to the fact that whitelisting all IPs hardly seems like a professional way to go about doing things.
What is a better solution?
You should only allow those IPs from which your application will connect to MongoDB Atlas. Allow all IPs is a bad practice and could make that MongoDB instance vulnerable.

Connecting to a mongoDB with a TCP prefix on a NodeJS application

I created a NodeJS app that connects with a MongoDB and it seems to work locally.
Now, after hosting the NodeJS application on a remote machine, I am trying to connect to a mongoDB that was already created on that machine. When I print out some of the environment variables, the only one I see of relevance seems to be :
MONGODB_PORT: 'tcp://172.30.204.90:27017',
I tried connecting like I usually do with
mongoose.connect('mongodb://localhost:27017/metadata/')
and replacing it with mongoose.connect('tcp://172.30.204.90:27017/metadata') but I get an error that says my URI needs to start with 'mongodb'.
So I tried replacing it with mongoose.connect('mongodb://172.30.204.90:27017/metadata') and it no longer throws any error. But on the MongoDB side I don't see any new connections happening and my app does not start up on the machine. What should I be putting in the URI?
Your URI should indeed start with mongodb:
mongoose.connect('mongodb://username:password#host:port/database?options...');
See this page for more information: https://docs.mongodb.com/manual/reference/connection-string/
Did you try to connect to the database from cli? Or Telnet to see that connection isn't blocked.

Ubuntu 14.04 with Node.js connection refused on routes

Using Express, I created a route /users which outputs some random strings. It works fine on my local machine. However, if I deploy my app on DigitalOcean, while viewing IP:port works, if I try my new route IP:port/users the server responds with "connection refused."
Any ideas what I am missing?
Here are the results of netstat:
i was definetly searching in the wrong place... it was the first time i got a "connection refused" from a server on an actual database error. i removed everything out of the actual route and really just used plain text as output. the problem was simple just a misconfiguration of the mysql connection and the database itself.
thanks anyways for the fast response and putting my wierd english words into the right order.

Resources