I am a beginner, Can anyone tell me why we have to need to import the whole schema into a new schema Object as an array? what's that Purpose?
pages: [nestedSchema]
E.g if I have
role_name: {
type: String,
},
pages: {
type: [nestedSchema],
},
});
const nestedSchema = new mongoose.Schema({
page_id: {
type: mongoose.Schema.Types.ObjectId,
ref: "page",
required: true,
},
view: {
type: Boolean,
default: true,
},
add: {
type: Boolean,
default: false,
},
edit: {
type: Boolean,
default: false,
},
delete: {
type: Boolean,
default: false,
},
});
I want to know why we need it To Place the Whole Schema into another as an Array. Because another way is available (refs&Populate), Is it Right to do it in this Way Or Not? If Yes then How do we get page[] array whole data just like (refs&populate) usage?