Can't connect to mongodb cluster (discord.js | mongoose) ECONRESET


#1

every time when I try to connect to my MongoDB cluster I get this error:

(node:23007) UnhandledPromiseRejectionWarning: Error: read ECONNRESET

at TCP.onread (net.js:622:25)

(node:23007) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated              either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

(node:23007) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the              future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

idk what I do wrong I already added the IP of my glitch project…

Here the code if you need it:
https://hastebin.com/arinutuwek.js


#2

Hmmm. Provided the connection string values are all correct that look right on the surface. Do you have any special characters (ones that would need to be url-encoded, for example) in your MONGOUSER or MONGOPASSWORD values?

If I were running into this problem I’d probably try putting the MONGOUSER and MONGOPASSWORD values in the file directly to make sure they’re correct (after putting that file in .gitignore temporarily to make sure your secrets don’t get committed to your git repo) or setting the MONGOPASSWORD to a very basic value temporarily.


#3

Now i’ve got
(node:23413) UnhandledPromiseRejectionWarning: MongoNetworkError: connection 0 to pydow-shard-00-02-xctzx.mongodb.net:27017 closed


#4

Maybe you could add an error handler into your mongoose.connect() call to examine the error returned and see if it provides any useful information? Like

mongoose.connect(uri, function(error) {
  // if error is truthy, the initial connection failed.
  console.log(error);
})

from here.


#5

Mhm

{ Error: read ECONNRESET

at TCP.onread (net.js:622:25)

name: 'MongoNetworkError',

errorLabels: [ 'TransientTransactionError' ],

[Symbol(mongoErrorContextSymbol)]: {} }

maybe TransientTransactionError helps…


#6

Uff im confused i can’t find any fix for that ._.


#7

I see this, but the solution there was to whitelist the IP, which you indicate you already did. Maybe double-triple-check the whitelist? Or open it up wider temporarily (I don’t know MongoDB that well so don’t know if that’s actually a thing you can do)?


#8

I have whitelisted now every IP (0.0.0.0) but still, don’t work…


#9

Well i try changing the cluster locaiton…


#10

I don’t think that address is going to provide you the whitelist you want - how did you determine the IP address you initially used?


#11

Nah im terminating this cluster now and try to host a server in the us


#12

I’ve got it… finally omg…
fix:
mongodb://USERNAME:PASSWORD@pydow-shard-00-00-15jok.mongodb.net:27017,pydow-shard-00-01-15jok.mongodb.net:27017,pydow-shard-00-02-15jok.mongodb.net:27017/test?ssl=true&replicaSet=Pydow-shard-0&authSource=admin&retryWrites=true


#13

Awesome, thanks for the description. Basically you need to include all members of the cluster in the connection string?

What did you end up with for your IP whitelist?


#14

Solution:
You should connect to every shard so there will be no connection problem anymore.
Example:

mongoose.connect(`mongodb://${process.env.MONGOUSER}:${process.env.MONGOPASSWORD}@pydow-shard-00-00-15jok.mongodb.net:27017,pydow-shard-00-01-15jok.mongodb.net:27017,pydow-shard-00-02-15jok.mongodb.net:27017/PydowDatabase?ssl=true&replicaSet=Pydow-shard-0&authSource=admin&retryWrites=true`,{
useNewUrlParser: true, 
}, function(error){console.log(error)});
  • you should host your MongoDB server in the USA so you can prevent connection issues.
  • add your bots up to the whitelist (check it with cmd (ping GLITCHPROEJECTNAME.glitch.me))
  • use the right format (you can find an example at MongoDB)

That should be all :slight_smile:
Happy coding!