MongooseError: 操作 `employees.deleteMany()` 在10000毫秒后超时缓冲。

huangapple go评论64阅读模式
英文:

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

问题

我一直在与这个Mongoose错误作斗争:MongooseError:操作employees.deleteMany()在10000毫秒后缓冲超时。请有人能帮我解决这个问题。

我尝试将数据种子化到MongoDB数据库,但一直收到缓冲超时错误。这是我的员工列表代码:

英文:

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:

答案1

得分: 0

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

首先,请检查您是否已正确连接您的数据库。如果您正在使用mongoose,您应该调用mongoose.connect。请参阅文档

通常,您会在另一个文件中执行此操作,并将其导入到您的server.js(或您需要的任何其他文件)文件中。确保正确调用该函数。

例如,如果您的数据库连接在名为connectDB的函数中定义如下:

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

您可以导入此函数并按以下方式调用它

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

以连接到数据库。

如果这不起作用,请检查您的网络连接。

英文:

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.

huangapple
  • 本文由 发表于 2023年5月14日 18:49:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76247059.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定