Estoy aprendiendo mongodb con mongoose (documentos normalizados) y tratando de entender cómo obtener datos a través del documento de referencia
const employeeSchema = new Schema({ name: String, email: String, }); const ContactSchema = new Schema({ email: String, mobile: String, fax: String, }); const DepartmentSchema = new Schema({ contact: ContactSchema, title: String, director: { type: Schema.Types.ObjectId, ref: 'Employees', }, }); const ChannelSchema = new Schema({ title: String, }); const StudentSchema = new Schema({ channel: { type: Schema.Types.ObjectId, ref: 'Channels', }, department: { type: Schema.Types.ObjectId, ref: 'Departments', }, name: { type: String, }, }); const Students = model('Students', StudentSchema); const Departments = model('Departments', DepartmentSchema); const Channels = model('Channels', ChannelSchema); const Employees = model('Employees', employeeSchema);Cómo lograr una consulta como la siguiente en mongoose
Students.find({ name: 'studentName' }); //Ok Students.find({ channel: { name: 'channelName' } }); Students.find({ department: { director: { name: 'directorName' } } }); Students.find({ department: { contact: { email: 'emailDirector' } } });La primera línea funciona como se esperaba.