Mongoose Schema hasn't been registered for model

前端 未结 17 895
猫巷女王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:31

    The issue is with the refs, always make sure to refer the refs to whatever name your are exporting from the models.

    // Model

    const Task = mongoose.model('**Tasks**', taskSchema);
    

    //Refs

    userSchema.virtual('tasks', {
    ref: '**Tasks**',
    localField: '_id', // field in current model
    foreignField: 'owner' // corresponding field in other model
    

    });

提交回复
热议问题