Hi, I just updated my Node.js from version “16.something” to “20.10.0” and while I am trying connect to MongoDB Atlas, my terminal is throwing following error:
And yes, it solved my issue, but I am concerning about two things:
Driver version “2.2.12 or later” is tagged as Non Stable API - is it okay?
When my Node.js was at version “16.something”, everything worked fine. So the question is about that issue is somewhere at Node.js itself if everything worked on older version.
Despite that I attempted many options with my DNS configurations, such as ipconfig /flushdns or using 8.8.8.8 and 8.8.4.4 addresses but none of them solved this issue. I also attempted multiple PC restarts, start the server at safe mode with networking and also tried different device on the same network. By the way I am using mongoose package and even upgrading it via npm, it neither helped. Any clues?
The post is recommending that the connection string from that dropdown is used it is not implying that versions is used nor does it actually impact whether Stable API is used or not.
Any version of the driver less than 3.7 does not support Stable API which is why it appears in the dropdown.
You should use the latest driver avaialable for your version of NodeJS.
With tons of reinstalls of Node.js I discovered that problem starts to appear from version 19.7.0 and up. On the previous version (19.6.1) and down all is working fine.
I hope for more answers here, maybe @Jason_Tran have some new ideas?
After some investigation, I’ve found the solution to my problem.
Because the error is from Node.js internal, not MongoDB driver, so the main issue is that Node.js cannot resolve the dns record. For my case, the DNS server which Node.js is connecting to is 127.0.0.53, which I’ve had problem with before. You can check by using this code snippet:
import dns from "node:dns/promises";
console.log(await dns.getServers());
// [ '127.0.0.53' ]
To solve above issue, I use this snippet, which is explicit set the DNS server inside Node.j:
import dns from "node:dns/promises";
dns.setServers(["1.1.1.1"]);