const SurveySchema = new Schema({
name: String,
pages: [ //um survey pode ter várias páginas
{
type: Schema.Types.ObjectId,
ref: 'Page'
}
]
});
const PageSchema = new Schema({
name: String,
description: String,
_type: String
});
const Page = mongoose.model('Page', PageSchema);
const Survey = mongoose.model('Survey', SurveySchema);
Let's say I have already populated information inside my bank ( Survey
):
{
_id: 'survey1',
name: 'Algum nome',
pages: ['58ff555', '123456789'] // Coleção de id's; cada id é uma página
}
How do I reference the above id?
If I do this in the way below, a random% wrap will be created and there will be no link to the template above.
var pag = new Page({
name: 'joeys',
description: 'descricao 1'
});
pag.save(function(err, model) {
if (err)
res.send(err);
res.json(model);
});
Another question: How to generate a single json with all the information from these two schemes at once?