TypeError: User is not a constructor

前端 未结 5 1534
长情又很酷
长情又很酷 2020-12-21 16:40

I am trying to save a user to mongodb database using post request as follow, but I got the error TypeError: User is not a function. It\'s a pretty simple set up

5条回答
  •  生来不讨喜
    2020-12-21 17:27

    // models/user.js
    var mongoose = require('mongoose');
    var Schema = mongoose.Schema;
    var UserSchema = new Schema({
        email: {
            type: String,
            unique: true,
            lowercase: true
    },
        password: String
    });
    
    var User = mongoose.model('User', UserSchema)
    module.exports =  { User } <-- capital 'U'
    

提交回复
热议问题