mongoose throw new TypeError('Model '的第二个参数必须是POJO或字符串,' + [已关闭]

qgzx9mmu  于 2022-12-27  发布在  Go
关注(0)|答案(1)|浏览(314)

**已关闭。**此问题为not reproducible or was caused by typos。当前不接受答案。

这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
11小时前关门了。
Improve this question
我刚刚创建了我的节点js服务器,当我指定模式和模型并将其添加到主服务器文件中时,它显示以下错误:

E:\py\.vscode\mern stack\backend\node_modules\mongoose\lib\model.js:115
    throw new TypeError('2nd argument to `Model` must be a POJO or string, ' +
    ^

TypeError: 2nd argument to `Model` must be a POJO or string, **not** a schema. Make sure you're calling `mongoose.model()`, not `mongoose.Model()`.
    at Mongoose.Model (E:\py\.vscode\mern stack\backend\node_modules\mongoose\lib\model.js:115:11)
    at Object.<anonymous> (E:\py\.vscode\mern stack\backend\user.js:7:27)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (E:\py\.vscode\mern stack\backend\server.js:2:14)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)

模式和模型的代码如下:

const mongoose = require('mongoose');
const userSchema = new mongoose.Schema({
    name: String,
    email: String,
    password: String
})
module.exports = mongoose.Model('USER', userSchema);
kr98yfug

kr98yfug1#

只写mongoose.model而不是mongoose.model。我希望问题会得到解决。

相关问题