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

前端 未结 16 1077
别跟我提以往
别跟我提以往 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:18

    I literally research lot and I found a solution so, I share this solution to you so, no one can face that cheap mistake that I did.

    Please remember, you just need to add the same name in ref as you gave in your model because its case sensitive ( Product !== product ).

    const Product = new mongoose.model('Product', productSchema);

    product: {
        type: mongoose.Schema.ObjectId,
        ref: 'Product', <-- Should be same as modelName
        required: [true, 'Cart must belong to a product']
    }
    

提交回复
热议问题