我的终端出现以下错误:
if (VALID_OPTIONS.indexOf(key) === -1) throw new Error(`\`${key}\` is an invalid option.`);
这是我的代码:
这是我得到的错误:
最佳答案
您得到的实际错误如下:
错误:“useCreateIndex”是无效选项。
这是第31行引起的:
mongoose.set("useCreateIndex", true);
useCreateIndex
在 Mongoose 6 及更高版本中始终默认为 true 且无法设置。
来自文档:
useNewUrlParser, useUnifiedTopology, useFindAndModify, and useCreateIndex are no longer supported options. Mongoose 6 always behaves as if useNewUrlParser, useUnifiedTopology, and useCreateIndex are true, and useFindAndModify is false. Please remove these options from your code.
为了将来引用,实际错误由 Error:
关键字及其后的所有内容表示,上面的部分仅指示哪些代码调用了手动抛出的错误。
关于Node.js Mongoose ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69716235/