mongoose icon indicating copy to clipboard operation
mongoose copied to clipboard

Problem connecting to MongoDB

Open joaobonifacio opened this issue 6 years ago • 9 comments

I've been doing an app in Angular, mongodb, express and using mongoose.

Until today I had no problems accessing my Atlas db.

I was using:

mongoose.connect("mongodb+srv://:@cluster0-xfp1v.mongodb.net/?retryWrites=true&w=majority") and all was fine.

Today I got connection failures and this deprecation warnings:

(node:37532) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect. (node:37532) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

I tryed using the connection string like:

mongoose.connect("mongodb+srv://:@cluster0-xfp1v.mongodb.net/?retryWrites=true&w=majority", { useNewUrlParser: true } )

and also

mongoose.connect("mongodb+srv://:@cluster0-xfp1v.mongodb.net/?retryWrites=true&w=majority", { useNewUrlParser: true, useUnifiedTopology: true } )

But nothing works. Does anyone has any ideas?

joaobonifacio avatar Apr 01 '20 17:04 joaobonifacio

Warning still persists for me as well if i set {useUnifiedTopology: true }

Enado95 avatar Apr 01 '20 23:04 Enado95

@joaobonifacio are you using any other MongoDB-related modules, like connect-mongo or connect-mongodb-session? Try running npm list | grep "mongo".

Also, please read our deprecation warning docs

vkarpov15 avatar Apr 02 '20 22:04 vkarpov15

@vkarpov15 see screen below. Im one node 12 and mongoose 5.9.7. Im connecting to replicaSet. Even after passing the option the warning still persists. useUnified

Enado95 avatar Apr 02 '20 23:04 Enado95

Just a shot in the dark, I've seen a couple of issues here where people had connection issues with Atlas that I wasn't able to reproduce, they turned out to be issues with their ISPs blocking Atlas for some reason.

Try changing your DNS to Google's 8.8.8.8, or try a VPN to see if the problem still persists.

EDIT: Oh, I didn't read that carefully enough, this is about the deprecation warnings, not a connection failure issue.

AbdelrahmanHafez avatar Apr 03 '20 00:04 AbdelrahmanHafez

Yes. I Read the docs. Did as recommend and the warning still persisted. As shown in the screenshot. @AbdelrahmanHafez

Enado95 avatar Apr 03 '20 00:04 Enado95

@Enado95 you did not answer my question. Run npm list | grep "mongo" and paste the output.

vkarpov15 avatar Apr 09 '20 19:04 vkarpov15

See below @vkarpov15 mongogrep

Enado95 avatar Apr 09 '20 19:04 Enado95

OK. Can you paste the code you're using to initialize winston-mongodb? This warning could be coming from that library as well.

vkarpov15 avatar Apr 11 '20 21:04 vkarpov15

That is in fact correct. The option was missing from that (winston-mongodb) connect method.

Enado95 avatar Apr 11 '20 21:04 Enado95