Search code examples
node.jsreactjsmongoosemongoose-schemanodejs-server

MongooseError: Operation `employees.deleteMany()` buffering timed out after 10000ms


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:


Solution

  • 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.