You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mongoose执行MongoDB数据库填充时遭遇操作缓冲超时错误求助

Mongoose执行MongoDB数据库填充时遭遇操作缓冲超时错误求助

大家早上好!

我正在做一个学校项目,最近在给MongoDB数据库填充种子数据的时候遇到了麻烦。每次运行提供的代码,都会弹出这个错误:MongooseError: Operation 'trips.deleteMany()' buffering timed out after 10000ms。

我已经确认MongoDB服务是正常运行的——不仅能用mongosh手动操作数据库,还能通过DBeaver这个GUI工具正常连接,所以实在搞不懂为什么Mongoose会出现连接问题。

我还按照其他帖子的建议,尝试在数据库连接操作和deleteMany()方法前都加上了await,但还是没能解决这个超时问题。

下面是我的seed.js代码片段:

// Brind in the DB connection and the Trip schema
const Mongoose = require('./db')
const Trip = require('./travlr');

// Read seed data from json file
var fs = require('fs');
var trips = JSON.parse(fs.readFileSync('./data/trips.json', 'utf8'))

// Delete any existing records, then insert seed data
const seedDB = async () => {
    await Trip.deleteMany({});
    // 后续插入种子数据的代码省略...
}

有没有大佬能帮我看看问题出在哪呀?

备注:内容来源于stack exchange,提问作者Nicholas Phelps

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.17 08:48:08