我正在尝试创建简单的CMS,并能够向网站添加新页面。我目前创建了一个名为Pages
的集合:
var PageSchema = new Schema({
name_en: {
type: String,
required: true
},
name_nl: {
type: String,
required: true
},
slug_en:{
type: String,
required: true
},
slug_nl:{
type: String,
required: true
},
content_en: {
type: String,
required: true
},
content_nl: {
type: String,
required: true
},
visible: {
type: Number,
required: true,
default: 1
},
is_headMenu: {
type: Number,
require: true,
default: 0
},
is_footerMenu: {
type: Number,
require: true,
default: 0
},
date: {
type: Date,
default: Date.now
}
});
此集合存储所有页面,但几天后我需要添加一个选项,以便将子页面存储到现有页面。 我正在考虑在页面模式中创建一个对象来保存所有子页面。
像这样:
var subPage = new Schema({
name_nl: {
type: String,
required: true
},
name_en: {
type: String,
required: true
},
slug_en:{
type: String,
required: true
},
slug_nl:{
type: String,
required: true
},
content_en: {
type: String,
required: true
},
content_nl: {
type: String,
required: true
},
visible: {
type: Number,
required: true,
default: 1
}
});
var PageSchema = new Schema({
name_en: {
type: String,
required: true
},
name_nl: {
type: String,
required: true
},
slug_en:{
type: String,
required: true
},
slug_nl:{
type: String,
required: true
},
content_en: {
type: String,
required: true
},
content_nl: {
type: String,
required: true
},
visible: {
type: Number,
required: true,
default: 1
},
is_headMenu: {
type: Number,
require: true,
default: 0
},
is_footerMenu: {
type: Number,
require: true,
default: 0
},
subPages: [
subPage
],
date: {
type: Date,
default: Date.now
}
});
但是我无法使用它,因为在创建Page
之后我需要填充对象'subPage',因为它是必需的。我不希望这样。我想随时添加它们,这样就不可能了。我该怎么做呢?