TypeError: User is not a constructor

前端 未结 5 1554
长情又很酷
长情又很酷 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:31

    I was also facing the same error but this worked for me.

    I did change my export file

    var User = mongoose.model('User',userSchema);
    module.exports = {User};
    

    To

    module.exports = mongoose.model('User', userSchema);
    

提交回复
热议问题