I have a schema like this for a family (whose children are enrolled in a school)...
var familySchema = new Schema({
parents: [{
firstName: String,
lastName: String,
email: String,
}],
students: [{
firstName: String,
lastName: String,
grade: Number,
}]
});
I'd like to describe many schools that contain classrooms, and have the classrooms contain students, something like this...
var schoolSchema = new Schema({
name: String,
street: String,
classrooms: [{
classroomNumber: Number,
students: [ /* I am mixed up here */ ]
}]
});
How do I tell mongoose that I want an array of object ids for students found in the other collection?
I understand from this answer that, if I wanted the classrooms to refer to family documents, I could say something like:
families: { type : ObjectId, ref: 'Family' }
but how do I do the same for sub-documents of another collection? (If it isn't obvious, I'm just learning both mongo and mongoose).