MERN stack cannot connect to mongoDB Atlas

I am learning from a MERN stack tutorial from youtube.


As you can see from the screenshot, I have already whitelist all IP address in Network Access page.

When I tried to connect from nodeJs server in my laptop there is an error message like screenshot below. I use driver version 2.2.12 or later - the old version - because version above 2.2.12 never works in my laptop :


Which mentions “one of common reason is IP isn’t whitelisted yet”
This confuses me because if I use the same version of connection string in my nextJs apps, it works just fine.

If I use newer version than 2.2.12, this is the error message :

And this is my server.ts file :

I go into a little more detail at querySrv errors when connecting to MongoDB Atlas | ALEX BEVILACQUA, but ultimately the issue is the DNS query for the SRV and TXT records required to construct the connection string from the mongodb+srv:// URI scheme is failing.

That’s why falling back to the mongodb:// URI scheme works.

Thanks Alex, I actually have found the solution : it was node version. I was using version 18, downgrade to version 16 solves the problem!