0

I can't connect to my app and it was working fine yesterday. I cant figure out why it's not working. I am running it locally, I have closed all ports and reset everything. I know this question isn't very direct but is their anything I should check in my code that I am missing based on this error?

I closed all ports, checked for connection string to link to MongoDB and changed and double checked my password. I might need to add some error handling catch() block but I wouldn't even know what and where to add it.

(node:24667) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [cluster0-shard-00-02-stguw.azure.mongodb.net:27017] on first connect [MongoNetworkError: connection 5 to cluster0-shard-00-02-stguw.azure.mongodb.net:27017 closed]
    at Pool.<anonymous> (/home/mat/code/goneGo/node_modules/mongodb-core/lib/topologies/server.js:431:11)
    at Pool.emit (events.js:198:13)
    at connect (/home/mat/code/goneGo/node_modules/mongodb-core/lib/connection/pool.js:557:14)
    at callback (/home/mat/code/goneGo/node_modules/mongodb-core/lib/connection/connect.js:109:5)
    at runCommand (/home/mat/code/goneGo/node_modules/mongodb-core/lib/connection/connect.js:129:7)
    at Connection.errorHandler (/home/mat/code/goneGo/node_modules/mongodb-core/lib/connection/connect.js:321:5)
    at Object.onceWrapper (events.js:286:20)
    at Connection.emit (events.js:198:13)
    at TLSSocket.<anonymous> (/home/mat/code/goneGo/node_modules/mongodb-core/lib/connection/connection.js:350:12)
    at Object.onceWrapper (events.js:286:20)
    at TLSSocket.emit (events.js:198:13)
    at _handle.close (net.js:606:12)
    at TCP.done (_tls_wrap.js:388:7)
(node:24667) 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:24667) [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.

I expect to type nodemon, and node spits out "connected at local host 3000 at port 27017 with 0 thing".

Sergio Pulgarin
  • 869
  • 8
  • 20
  • You should definitely show the code that you are using to connect. A `catch` block could help getting a more specific and helpful error message. If you connection worked on this exact code and this machine, my guess is that you MongoDB server simply is not running. Did you restart your computer? Do you remember running the service manually? – Sergio Pulgarin Aug 25 '19 at 05:30
  • This isn't specific to MongoDB but could help you implementing the `catch` part: https://stackoverflow.com/questions/53940043/unhandledpromiserejectionwarning-this-error-originated-either-by-throwing-insid. – Sergio Pulgarin Aug 25 '19 at 05:31
  • `const mongoose = require('mongoose'); // mongoose.connect('mongodb://localhost/test', {useNewUrlParser: true}); mongoose.connect(process.env.DATABASE_URL, { useNewUrlParser:true, }); const db = mongoose.connection db.on('connected', function(){ console.log(`Connected to MongoDB at ${db.host}:${db.port} that contains ${db.modelNames.length} things`) }) module.exports = mongoose` – Matthew Robin Aug 25 '19 at 06:30

0 Answers0