0

I have a data like follows

 "student" : [ 
ObjectId("58500ea5ef914125073b040f"),
ObjectId("58500ea5ef914125073b042e")

],

my model,

  student: [{type: Schema.ObjectId,ref: 'Student'}],

I want to populate student in these array,

  Classroom.findById(id).populate('student.student'){}

It is not working,can anyone please suggest help.Thanks.

6
  • Did you add ref to your model's schema student:[{ type: Schema.Types.ObjectId, ref: 'Student' }] Commented Dec 14, 2016 at 7:12
  • Yes i did it..... Commented Dec 14, 2016 at 7:15
  • Could you show your schemas' code, and make sure you have appropriate data to populate in db. Commented Dec 14, 2016 at 7:16
  • Please post your Classroom schema. Commented Dec 14, 2016 at 7:19
  • Hi posted my schema. Commented Dec 14, 2016 at 7:21

1 Answer 1

1

From what i can see in your data, student is the array of students, so you need to just write student in the populate query.

this should work for you :

Classroom.findById(id).populate('student').exec(function(err,result){
    ...
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.