2015-04-06 56 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