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

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

    I got this error while trying to use mongoose-fixture to seed some default data into a mongo collection. Was baffled for long, following this and similar threads for help, trying to debug. Ultimately the issue turned out to be due to mongoose and mongoose-fixture versions in my case.

    If no code changes help, or if you get this error while trying to correctly use mongoose-fixture (which is supposed to register your schemas for you), try this. Delete the node_modules dir of your project, run an npm cache clean, and then an npm install.

    If even this doesn't help, try comparing versions of mongoose / mongoose-fixture between the problematic app and one that works, and try changing the version in your package.json, and repeating the above steps. This worked for me.

提交回复
热议问题