英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论