Mongoose Schema hasn't been registered for model

前端 未结 17 880
猫巷女王i
猫巷女王i 2020-11-27 15:00

I\'m learning the mean stack and when I try to start the server using

npm start

I get an exception saying that:

schema has         


        
17条回答
  •  感情败类
    2020-11-27 15:53

    I was also facing the same problem. The solution to my problem was looking at the ref parameter which had a different name compared to the model I was actually exporting and hence no such model was found.

    userSchema.virtual('tasks', {
        ref: 'Task',
        localField: '_id',
        foreignField: 'owner'
    })
      
    

    Whereas what I had actually exported was :-

    const Tasks = mongoose.model('Tasks', taskSchema)
    
    module.exports = Tasks
    

    After rectifying the Task as Tasks my problem was solved

提交回复
热议问题