0

I have been battlling with this mongoose error: MongooseError: Operation employees.deleteMany() buffering timed out after 10000ms. Pleae can someone help me out here.

. I tried to seed my data to the mongoDB database, but keep getting the buffering timeout error. Here is my employees list code:

  • Have you called `mongoose.connect`? – kennarddh May 14 '23 at 11:13
  • 1
    Does this answer your question? [How to solve Mongoose v5.11.0 model.find() error: Operation \`products.find()\` buffering timed out after 10000ms"](https://stackoverflow.com/questions/65090440/how-to-solve-mongoose-v5-11-0-model-find-error-operation-products-find-bu) – Moshe Fortgang May 14 '23 at 11:14
  • Yes, import mongoose from 'mongoose' const connectDB = async () => { try { const conn = await mongoose.connect(process.env.MONGO_URI, {}) console.log(`MongoDB Connected: ${conn.connection.host}`.cyan.underline) } catch (error) { console.log(`Error: ${error.message}`.red.underline.bold) process.exit(1) } } export default connectDB – Aja Edward May 14 '23 at 11:53
  • Did you import and call that function in your main entry point? Or can you add `console.log` inside your function to check if its called or not. – kennarddh May 14 '23 at 12:47

1 Answers1

0

Buffering timeout errors usually occur due to failed database connections caused by non-connected DB or network issues.

Firstly, check if you have correctly connected your database. If you are using mongoose, you should call mongoose.connect. See the documentation.

Usually, you would do this in another file and import it into your server.js (or whatever file you need it) file. Make sure you call the function properly.

For example if your db connection is defined in a function connect db as follows:

 const connectDB = async() => {
  try {
    await mongoose.connect('mongodb://127.0.0.1:27017/test');
  } catch (error) {
    handleError(error);
  }
}

You can import this function and call it as follows

  (async() => {
    await connectDB()
   })()

to connect to database.

If this doesnt work then check your network conenction.