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

MERN项目报MongoParseError: option useCreateIndex is not supported如何解决

问题解决方法

根因

你使用的Mongoose版本为v6.0及以上版本,旧版本Mongodb连接所需的useNewUrlParser、useUnifiedTopology、useCreateIndex三个配置项已经被框架默认启用,不再支持手动传入连接配置,传入不存在的配置项就会触发本次的MongoParseError错误。

修复方案

直接移除mongoose.connect方法的第二个配置参数即可,修正后的完整代码如下:

const mongoose = require("mongoose");

module.exports = async() => {
  try {
    await mongoose.connect("mongodb://localhost/todo-app");
    console.log("Connected to database.");
  } catch (error) {
    // 顺带修复原代码里的语义冗余错误:could not和able to重复
    console.log("Could not connect to database.", error);
  }
};

内容的提问来源于stack exchange,提问作者Niromy

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.30 05:57:02