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

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:

1 Like

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.

Now i’ve got
(node:23413) UnhandledPromiseRejectionWarning: MongoNetworkError: connection 0 to closed

1 Like

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.

from here.


{ Error: read ECONNRESET

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

name: 'MongoNetworkError',

errorLabels: [ 'TransientTransactionError' ],

[Symbol(mongoErrorContextSymbol)]: {} }

maybe TransientTransactionError helps…

1 Like

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

1 Like

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)?

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

1 Like

Well i try changing the cluster locaiton…

1 Like

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?

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

1 Like

I’ve got it… finally omg…

1 Like

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?

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

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
  • use the right format (you can find an example at MongoDB)

That should be all :slight_smile:
Happy coding!


This thread helped me out SO much. I had same issue w mongo! thank you for sharing code snippet OP.


after adding all the shards i got this error:

MongoParseError: Invalid URI, cannot contain multiple hostnames

1 Like

Hey @sailesh97, welcome to the Glitch forum!

Can you share your connect code so we can take a look?

A post was split to a new topic: Can’t connect to MongoDB

I have the problem that he had initialy, My code just doenst look like his and I dont understand what his fix was, can you please help me understand?

Hello ItzOso, if you are having a different problem I recommend you start a separate post to keep things organized.