My database schema involves managing families with children enrolled in school. Here's an example schema for the family:
var familySchema = new Schema({
parents: [{
firstName: String,
lastName: String,
email: String,
}],
students: [{
firstName: String,
lastName: String,
grade: Number,
}]
});
Now, I want to design a schema for schools that include classrooms containing students. This is how I envision it:
var schoolSchema = new Schema({
name: String,
street: String,
classrooms: [{
classroomNumber: Number,
students: [ /* Unsure about this part */ ]
}]
});
How can I specify to mongoose that I want an array of object IDs referencing students from the family collection?
I came across this answer which explains how to reference documents from another collection like families:
families: { type : ObjectId, ref: 'Family' }
But how do I achieve the same for sub-documents belonging to another collection? As a beginner in mongo and mongoose, I'm seeking clarity on this.