Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

86
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!