0

I have 3 collections each related to the other. Let's assume that first collection is University:

{
  _id: ObjectId(),
  name: '',
  description: '',
  creation_date: '',
  address: ''
}

And Teacher collection:

{
  _id: ObjectId(),
  name: '',
  university_name: '',
  dob: ISODate('')
}

And the final collection is TeacherScore:

{
  _id: ObjectId(),
  teacher_name: '',
  score: 10
}

You may ask that score can be in teacher collection, but this is a sample scenario and in the real world example it is a very different entity that we need to keep it separate.

In our pipeline we first join University with Teacher based on university_name foreignField using $lookup so we have list of universities with list of teachers inside of it:

[{
      _id: ObjectId(),
      name: '',
      description: '',
      creation_date: '',
      address: '',
      teachers: [{
        ...
      }]
}]

Question is that users search based on teacher score. How can I join TeacherScore with teachers inside university and then search/match based on his/her score?

NOTE: I need to reach to score from university that's why my base is on university and then I will reach to teacher and finally to score.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.