I have a schema called PageSection. PageSection embeds an array of the Schema ContentItem. A content item should reference to a documents of other collections, which can be variable - like Text, Picture, Link, Checkbox, ...
var PageSection = new mongoose.Schema({
title: String,
order: Number,
contentItems: [{
order: Number,
element: {
type: mongoose.Schema.Types.ObjectId,
path: "Path_to_various_models"
}
}]
});
Is this possible? Or is there an better way to that kind of variable references?
Thanks!
Edit: Thanks for advice for using discriminators Swagata. I didn't knew that inheritance mechanism. But anyway, I found that solution a bit complex.
I now use a solution, where ContentItem contains a field for each type of content item. Maybe its more a workaround, than a solution.
var PageSection = new mongoose.Schema({
title: String,
order: Number,
contentItems: [{
order: Number,
text: {
type: mongoose.Schema.Types.ObjectId,
path: "Text"
},
picture: {
type: mongoose.Schema.Types.ObjectId,
path: "Picture"
},
link: {
type: mongoose.Schema.Types.ObjectId,
path: "Link"
}
}]
});