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

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

    In using express, one of the common mistake is by requiring the express before mongoose. This results to "MissingSchemaError: Schema hasn't been registered for model "User"." error.

    You can easily fix it by correcting the "require" order (i.e mongoose then express)

    var mongoose = require('./config/mongoose'), 
        express = require('./config/express');
    

提交回复
热议问题