1
Imagining the following structure(Merely illustrative example):
Collection: Schools
[
{
"_id":"abc123",
"nomeEscola":"escola1",
"turmas":{
"_id":"ccc333",
"nomeTurma":"Turma1"
}
},
{
"_id":"abc122",
"nomeEscola":"escola2",
"turmas":{
"_id":"ddd444",
"nomeTurma":"Turma1"
}
}
]
Now, let’s say I go create a new student charter, and I want her schema in Mongoose have the ID
of TURMA
and nay of ESCOLA
Alunomodel:
let mongoose = require('mongoose');
Schema = mongoose.Schema;
let alunoSchema = new Schema({
_id : {type: Schema.Types.ObjectId},
nomeAluno : {type: String},
idTurma: {type: Schema.Types.ObjectId, ref : 'Escolas'},
}, {collection : 'Alunos'});
var aluno = mongoose.model('Aluno', alunoSchema);
module.exports = aluno;
How do I ensure that
idTurma
go reference the Class id and not the School id?
thank you very much!
– user94991