MongooseError: Operation `users.findOne()` buffering timed out

same issue

Hi @Hamid_Ali,

Welcome to the MongoDB Community forums :sparkles:

It seems that the issue you’re facing could be due to the database not being connected. Could you please ensure the following:

  • Confirm that your database is connected, and your code is pointing to the correct URL.
  • Check if your mongoose.connect(...) code is loading properly.
  • Verify the structure of your code, especially if you’re running into issues when the mongoose.connect code is in a different file. Make sure to require that file in your main index.js file.

Additionally, as per the Mongoose documentation at The model might be called before the connection is established.

To resolve this, consider using async/await with connect() or createConnection() or use .then(), as these functions return promises starting from Mongoose 5.

Here’s an example code snippet for your reference:

const dbconnect = async () => {
  await connect('<MongoDB_URI>');
  console.log("Connected to Database");

  .catch((err) => console.error(err))

Make sure to adapt your code accordingly to incorporate these suggestions. I hope it helps!

Best regards,