【问题标题】:throw new TypeError('2nd argument to `Model` must be a POJO or string, ' +throw new TypeError(\'2nd argument to `Model` must be a POJO or string, \' +
【发布时间】:2022-12-26 13:33:42
【问题描述】:

i just created my node js server and when i specified the schema and model and added it ins the main server file it is showing following error:

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)

and the code of schema and model is as given below:

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

【问题讨论】:

  • From the error stack: TypeError: 2nd argument to Model` must be a POJO or string,nota schema. Make sure you're calling mongoose.model(), not mongoose.Model().`

标签: node.js mongodb web mongoose mern


【解决方案1】:

just write mongoose.model instead of mongoose.Model. I hope problem will be solved.

【讨论】:

    猜你喜欢
    • 2012-05-15
    • 1970-01-01
    • 1970-01-01
    • 2016-11-13
    • 1970-01-01
    • 1970-01-01
    • 2019-12-29
    • 1970-01-01
    • 2017-03-09
    相关资源
    最近更新 更多