Automattic / mongoose

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

Unable to connect to MongoAtlas via Mongoose #6659

Closed csnktms closed 6 years ago

csnktms commented 6 years ago

Unable to connect to MongoAtlas free tier w/ Mongoose.

Error No 1.: seed list contains no mongos proxies, replicaset connections requires the parameter replicaSet to be supplied in the URI or options object, mongodb://server:port/db?replicaSet=name

Connect function: mongoose.connect(`mongodb+srv://admin:${pass}@nodeapp-alni3.mongodb.net/nodeapp?retryWrites=true`);

Where should I get this repl-set name? It suggested to use repl-set-shard-0 or something like that. With these configurations the second error popup is that auth failed. I have tried my pass hardcoding, extracting it to variables, and generating new passwords. Nothing works 🥇

rjsalem commented 6 years ago

Hi I am having the same issue. Currently using mongoose 5.2.0.

lineus commented 6 years ago

Until mongoose 5.2.1 comes out, you need to make sure your authSource and replicaSet vars are set in the options object instead of the uri. You must also specify the port explicitly. Check out issues 6647-6651 for more details. Let us know if you have any further trouble getting connected.

lineus commented 6 years ago

@csnktms You can find your replicaSet value in the atlas console, it’s in the older driver connection string for sure and probably a few other places. Let me know if you still need help, I’ll be back at my computer early in the morning EDT.

andresochoas commented 6 years ago

The error is caused by this commit.

You only need to set useNewUrlParser equal to true in options.

rjsalem commented 6 years ago

I tried it didn't change anything.

andresochoas commented 6 years ago

Sure? Try to downgrade you Mongoose version to ~5.0.14. Remember update your package-lock.json or equivalent.

rjsalem commented 6 years ago

I downgraded to 5.1.8 and it's working without anything.

@csnktms in package.json use -> "mongoose": "5.1.8"

lineus commented 6 years ago

@AndyOchoaS That commit was never published to npm. It’s already been replaced with a better solution. 5.2.0 forced the value to true and didn’t let you set it in the connection options, 5.2.1 will.

Setting usenewurlparser to true is what breaks mongoose 5.2.0 because the 3.1.0 driver shipped with a bug in the new url parser. All of this is documented in bugs created in the last 24 hours.

vkarpov15 commented 6 years ago

Upgrade to 5.2.1, just released and should fix this issue. See #6656

lineus commented 6 years ago

Nice! Thanks @vkarpov15!!!