埋め込まれたドキュメントで奇妙な動作に遭遇しました。何か間違ったことをしたのか、それともバグなのかわかりません。私はこのようにExameスキーマを定義しました
var ExameSchema = new Schema({
_perguntas: [{
type: Schema.ObjectId,
ref: 'Pergunta'
}],
created: {
type: Date,
default: Date.now
}
});
私のPerguntaスキーマはこのようなものです
var PerguntaSchema = new Schema({
created: {
type: Date,
default: Date.now
},
_exame: {
type: Schema.ObjectId,
ref: 'Exame',
required:'Um pergunta tem de estar associado a uma Exame'
},
_alternativas:[{
type:Schema.ObjectId,
ref:'Alternativa'
}]
});
そして私の Alternativa スキーマはこのように
var AlternativaSchema = new Schema({
conteudo: {
type: String,
default: '',
//required: 'Please fill Alternativa conteudo',
trim: true
},
created: {
type: Date,
default: Date.now
},
pergunta: {
type: Schema.ObjectId,
ref: 'Pergunta'
}
});
を呼び出す
Exame.find().populate('_perguntas')
と、試験オブジェクトに配列内の perguntas オブジェクトが取り込まれますが、公式ドキュメントに記載されているようにExame.find().populate('_perguntas').populate('_alternativas');
orExame.find().populate('_perguntas').populate('_perguntas._alternativas');
を呼び出すと、_perguntas オブジェクトに代替ドキュメントが取り込まれず、代わりに objectId の配列が返されます。誰か教えてください-どこで間違ったのですか??