MissingSchemaError: Schema hasn't been registered for model “User”

前端 未结 16 1076
别跟我提以往
别跟我提以往 2020-12-02 16:56

In my models/user.js file:

var mongoose = require(\'mongoose\');
var Schema = mongoose.Schema;

var userSchema = new Schema({
    (define schema         


        
16条回答
  •  温柔的废话
    2020-12-02 17:21

    I was making a different mistake like I have created the Schema but the issue was that I didn't use schema model (for insert, update, read and delete the doc).

    i.e. I have created the collection something like that:

    const playerSchema = new Schema({
        bowling: {
            style: String,
            arm: String,
        }
    })
    
    export const PlayerSchema = model('Player', playerSchema)
    

    but didn't use or call PlayerSchema model somewhere that's why I was getting this error.

提交回复
热议问题