Automattic / mongoose

MongoDB object modeling designed to work in an asynchronous environment.
https://mongoosejs.com
MIT License
26.99k stars 3.85k forks source link

connecting to MongoDB Atlas, #14917

Open Joshua-alt opened 1 month ago

Joshua-alt commented 1 month ago

Prerequisites

Mongoose version

8

Node.js version

18.14.1

MongoDB server version

MongoDB Atlas

Typescript version (if applicable)

No response

Description

I’m encountering a problem connecting to MongoDB Atlas, even though I’ve allowed network access for everyone by adding ‘0.0.0.0/0’ to the IP whitelist using mongoose v8

Steps to Reproduce

to get issue that i show in description can be done by install mongoose 8v then connect it with mongodb atlas and to fixe required to back on "mongoose": "^7.3.2" version that for me is working fine

Expected Behavior

I’m encountering a problem connecting to MongoDB Atlas, even though I’ve allowed network access for everyone by adding ‘0.0.0.0/0’ to the IP whitelist. When attempting to connect, I consistently receive the following error message: ‘MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you’re trying to access the database from an IP that isn’t whitelisted. Make sure your current IP address is on your Atlas cluster’s IP whitelist

akang commented 1 month ago

I am facing the same issue.

For me:

Breaks on version 8.7.0 Works on 8.5.2

mtrplx commented 1 month ago

worked for me too!! thank u very much i was going INSANE

vkarpov15 commented 1 month ago

What version of the MongoDB server are you running in Atlas?

akang commented 1 month ago

@vkarpov15

7.0.12

mtrplx commented 1 month ago

7.0.14

kumarchetan-1 commented 1 month ago

Yes, "mongoose": "^7.0.12" is working for me. Thank you @akang!

vkarpov15 commented 1 month ago

A couple of potential suggestions:

  1. Does your database username or password contain special characters that would be encoded by encodeURIComponent()?
  2. Are you able to connect using the mongodb node driver?
  3. What is the output of err.reason where err is the MongooseServerSelectionError?
lukas-becker0 commented 1 month ago

We have no issues with mongoose 8.6.4 and mongodb 7.0.12 on mongodb atlas.

angelosnm commented 1 month ago

Same behaviour here....mongoose 8.7.0 and mongodb atlas 8.0.0

bmortella commented 1 month ago

Same! Atlas 7.0.14 Fixed by rolling back to mongoose 8.6.1.

lukas-becker0 commented 1 month ago

Strange we also use Atlas 7.0.14 now and mongoose 8.6.4 without this connection issue.

How do you guys connect to the server ?

mongodb+srv://DB-USER:PASSWORD@ATLAS-INSTANCE-NAME.dyvqc.mongodb.net/?retryWrites=true&w=majority

serverSelectionTimeoutMS is set to 5000 ms

And the DB name is not included in the URL option, it is passed separately through the mongoose dbName option.

lukas-becker0 commented 1 month ago

We only use linux and macOS maybe this is a windows issue ?

angelosnm commented 1 month ago

We only use linux and macOS maybe this is a windows issue ?

Nope. I came with this issue on deployment, obviously on linux server.

vkarpov15 commented 1 month ago

I tried with a separate dbName option and no dbname in the connection string, I'm still able to connect successfully to Atlas with Mongoose 8.7. @angelosnm are you able to provide any additional information?

angelosnm commented 3 weeks ago

I tried with a separate dbName option and no dbname in the connection string, I'm still able to connect successfully to Atlas with Mongoose 8.7. @angelosnm are you able to provide any additional information?

I still had issues. What fixed it was downgrading package version.

chibuzodaniel commented 2 weeks ago

been battling the same Issue. Downgrading the Mongoose package version fixed it @angelosnm

github-actions[bot] commented 3 hours ago

This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days