我正在使用SimpleSchema和Meteor来构建数据库条目。
问题是,我有一个数组数组,定义的模式不起作用。
这是一个文档示例:
Courses.insert({
"persian_title":"persian title",
"english_title":"english title",
"free_for_all":true,
"price":1000,
"is_offer":false,
"offer_price":500,
"Seasons":[
{
"title":"first Season",
"free_for_all":false,
"Episodes":[
{
"title":"first Episode",
"length":"12:10:00",
"url":"test"
},
{
"title":"second Episode",
"length":"0:10:00",
"url":"test"
},
{
"title":"third Episode",
"length":"14:10:00",
"url":"test"
}
]
},
{
"title":"Second Season",
"free_for_all":false,
"Episodes":[
{
"title":"first Episode",
"length":"12:10:00",
"url":"test"
},
{
"title":"second Episode",
"length":"0:10:00",
"url":"test"
},
{
"title":"third Episode",
"length":"14:10:00",
"url":"test"
}
]
}
]
})
和架构:
Courses = new Mongo.Collection("courses");
var Schemas = {};
Schemas.Courses = new SimpleSchema(
{
persian_title: {
type: String
},
english_title: {
type: String
},
free_for_all: {
type: Boolean
},
price: {
type: Number
},
is_offer: {
type: Boolean
},
offer_price: {
type: Number
},
// Seasons
"Courses.$.Seasons": {
type: [Object]
},
"Courses.$.Seasons.$.title": {
type: String
},
"Courses.$.Seasons.$.free_for_all": {
type: Boolean
},
// Episodes
"Courses.$.Seasons.$.Episodes": {
type: [Object]
},
"Courses.$.Seasons.$.Episodes.title": {
type: String
},
"Courses.$.Seasons.$.Episodes.length": {
type: String,
max: 8
},
"Courses.$.Seasons.$.Episodes.url": {
type: String,
max: 1000
}
});
Courses.attachSchema(Schemas.Courses);
简单架构文档:https://github.com/aldeed/meteor-simple-schema#schema-keys
问题是如何为数组数组定义Schema?
答案 0 :(得分:1)
您必须使用PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER
在架构中明确定义Seasons.$.Episodes
。定义Seasons数组对象的模式,如下所示:
type: [Object]