35 / 35
Apr 4

i already whitelisted my ip but still error but if i set ip to 0.0.0.0/0 it works but i dont want to set it to 0.0.0.0/0 i want to set it to my own ip address. do you have any solution?

It happened to me when I upgraded mongo node.js driver from 6.3.0 to 6.9.0.
Downgrading back to 6.3.0 and the issue is gone.

update: I updated my node version the latest LTS (v20.17.0) and everything is working fine with the new driver

it seems there is an issuea with “6.9.0”, downgrading “6.1.0” (which I use my older projects) worked for me

18 days later

Apparently, the issue is on version 6.9.0 which contains a breaking change:

Here are two ways I found to overcome this issue:

  1. downgrading to a lower version (6.8.2 for ex)
  2. passing autoSelectFamily: false overriding the default value of true

Hope someone on MongoDB will see this discussion and revert this breaking change, or alternatively - document this as a breaking change on their release notes.

P.S.
I would totally understand if this new behavior was communicated on previous release notes, allowing developers to get prepared for that (+ adding a runtime warning might do as well), but since I didn’t find any evidence for that - it is a breaking change published out on 6.9.0 without any prior notification.

Here a code that solve the issue for me:

const { MongoClient } = require("mongodb"); const uri = "mongodb+srv://<name>:<pw>@<server>/<db></db>?retryWrites=true&w=majority"; const client = new MongoClient(uri, { tls: true, serverSelectionTimeoutMS: 3000, autoSelectFamily: false, }); async function connectToDatabase() { try { await client.connect(); console.log("Connected to MongoDB successfully."); // Add your database operations here } catch (error) { console.error("Connection failed", error); } finally { await client.close(); } } connectToDatabase();
14 days later
10 days later

if you mongoose version is 8> the problen never disapire you need to use a old version like 6 or 7 that resolved the error

Than you so much, I’m new to Mongodb so this was very frustrating experience… Youre suggestion to use autoSelectFamily: false solved the problem!

18 days later

Im trying to connect to my database from Render, when i do it locally it works but when i deploy my app on render it dosent i get the same error i tried lowering the version and autoSelectFamily false but nothing works

const client = new MongoClient(uri, {
serverApi: {

autoSelectFamily: false },

});

this is my client idk if here is the problem or what, im using atlas and put the 0.0.0.0 to allow all conections but nothing

19 days later

this error comes me to and i just install the latest version and the error gone. there is the comment npm i mongodb@latest

I upgraded to node version 20 along with “mongodb”: “^6.12.0”,
It solved the issue.

3 months later

Add 0.0.0.0/0 as an IP address (if at all security is not your concern) in network access tab