为什么这个插入模式附加集合无效?
Why is this insert into a schema attached collection invalid?
比方说,我们有这个模式:
Schemas.MyCollection = new SimpleSchema({
something: {
type: Object
}
});
我想在 MyCollection
中插入一些内容。例如:
var myobj = {
aaaaaa: 11111,
bbbbbb: 22222
};
MyCollection.insert({something: myobj});
我们最终得到这个:
{
_id: "someId",
something: {}
}
当我禁用简单模式检查 (collection2) 时,一切都按预期工作。
Simple-schema 没有报错(collection2)为什么无效?
@Seraph 你的模式是错误的
Schemas.MyCollection = new SimpleSchema({
something: {
type: Object
},
'something.aaaaa': {
type: String
}
});
等等你必须写每个 属性 对象有或者你可以做 blackbox: true
如果你不想验证对象:
something: {
type: Object,
blackbox: true
}
此外,如果它是服务器端操作,您可以执行 myCollection.insert(doc, {validate: false});
这里是帮助你理解更多的参考:
比方说,我们有这个模式:
Schemas.MyCollection = new SimpleSchema({
something: {
type: Object
}
});
我想在 MyCollection
中插入一些内容。例如:
var myobj = {
aaaaaa: 11111,
bbbbbb: 22222
};
MyCollection.insert({something: myobj});
我们最终得到这个:
{
_id: "someId",
something: {}
}
当我禁用简单模式检查 (collection2) 时,一切都按预期工作。
Simple-schema 没有报错(collection2)为什么无效?
@Seraph 你的模式是错误的
Schemas.MyCollection = new SimpleSchema({
something: {
type: Object
},
'something.aaaaa': {
type: String
}
});
等等你必须写每个 属性 对象有或者你可以做 blackbox: true
如果你不想验证对象:
something: {
type: Object,
blackbox: true
}
此外,如果它是服务器端操作,您可以执行 myCollection.insert(doc, {validate: false});
这里是帮助你理解更多的参考: