【发布时间】:2016-07-27 11:50:49
【问题描述】:
我正在使用 aldeed:collection2 和 aldeed:simple-schema 包。我想根据架构验证文档。我的架构包含例如一个带有 allowedValues 数组和一个嵌套对象数组的字符串字段,用子模式描述。像这样:
...
type: {
type: String,
allowedValues: [ 'A', 'B', 'C' ],
defaultValue: 'A',
index: 1,
},
nestedStuff: {
type: [ new SimpleSchema(nestedStuffSchema.schema(Meteor, SimpleSchema)) ],
defaultValue: [],
},
...
我有一个“坏”的文档,例如type 字段中的“D”和无效的嵌套数组项。
在客户端,我正在尝试:
Contacts.simpleSchema().namedContext().validate(badDoc);
它返回true。 SimpleSchema 说文档是有效的,即使它的字段不遵守模式。
单独验证“错误”type 字段也会返回 true。
我究竟做错了什么?为什么 SimpleSchema 可以假设随机的东西是有效的?
【问题讨论】:
标签: validation meteor meteor-collection2 simple-schema