Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

87
Vistas
Mongoose filter document

I'm learning mongodb with mongoose (normalized documents) and trying to understand how to fetch data accross referenced document

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);

How to achieve a query like below in mongoose

Students.find({ name: 'studentName' }); //Ok
Students.find({ channel: { name: 'channelName' } });
Students.find({ department: { director: { name: 'directorName' } } });
Students.find({ department: { contact: { email: 'emailDirector' } } });

The first line work as expected

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda