2015-04-06 50 views
11

我有一个字段为type: Object的模式。但是,每当我做一个插入,该对象是空的。用流星简单模式在场中存储任意对象

这里是我的架构

Contacts.attachSchema(new SimpleSchema({ 
    firstName: { 
     type: String, 

    }, 
    lastName: { 
     type: String, 
     optional: true 
    }, 
    twitterFriend: { // this field 
     type: Object, 
     optional: true 
    } 
})); 

即使做Contacts.insert({firstName: 'Mustafa', twitterFriend: {test: 'this should be stored'}})。这是行不通的。

回答

17

任意子模式的一个对象,你设置blackbox: true

Contacts.attachSchema(new SimpleSchema({ 
    firstName: { 
     type: String, 

    }, 
    lastName: { 
     type: String, 
     optional: true 
    }, 
    twitterFriend: { // this field 
     type: Object, 
     optional: true, 
     blackbox: true 
    } 
})); 

见SimpleSchema docs以供参考。

+0

感谢队友,我知道它必须在那里 – MurWade 2015-04-06 04:31:38

+0

这似乎并没有工作,这就像SimpleSchema只是忽略黑匣子? – Jan 2016-10-10 17:24:20

+0

@Jan您可能需要在另一个问题中发布您的代码,然后将其链接到它。也许别的东西稍微偏离? – 2016-10-11 21:13:50