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
相关产品推荐
相关产品推荐

