I want to add favorite teachers id to student schema from list of teachers. So when the student clicks the "add favorite teacher " button, that particular teacher id will save in the student schema.
Here is my student schema
const mongoose = require ('mongoose')
const studentSchema=new mongoose.Schema({
name:{type:String,required:true},
email:{type:String,required:true},
phone:{type:String,required:true},
password:{type:String,required:true},
teacher : [{type : mongoose.Schema.Types.ObjectID , ref:'teachers'}],
})
const studentModel = mongoose.model('students',studentSchema)
module.exports=studentModel
Here is my teacher Schema
const mongoose = require ('mongoose')
const teacherSchema=new mongoose.Schema({
name:{type:String,required:true},
email:{type:String,required:true},
phone:{type:String,required:true},
password:{type:String,required:true},
})
const teacherModel = mongoose.model('teachers',teacherSchema)
module.exports=teacherModel
So what will be the backend route code to push the teacher id to Student schemas ?