Handling Rejected Promises - request hanging infinitely

  • LESSON: “Handling and Logging Errors/ Handling Rejected Promises”

  • PROBLEM: After having modified the genre module adding the try-catch block in the get handler and stopping the mongodb daemon, the GET request in Postman is hanging infinitely.

  • IMPACTED VERSIONS: “mongoose”: “^5.0.1”

If someone has experienced the same issue, I solved it by:
adding a ConnectionOptions in the connect method to the db
Precisely in my index.js I modified the following line of code:

mongoose.connect('mongodb://localhost/vidly', { bufferCommands: false })
.then(() => console.log('Connected to MongoDB...'))
.catch(err => console.error('Could not connect to MongoDB...', err));
  • DEFINITION FROM REFERENCE LINK:
    option: bufferCommands
    By default, mongoose buffers commands when the connection goes down until the driver manages to reconnect. To disable buffering, set bufferCommands to false.
1 Like
    { bufferCommands: false }

Did not work in my case. Request still hangs infinitely.