使用流星简单模式在字段中存储任意对象

Mus*_*afa 12 meteor meteor-collection2

我有一个字段的架构type: Object.但每当我进行插入时,该对象都是空的.

这是我的架构

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

    },
    lastName: {
        type: String,
        optional: true
    },
    twitterFriend: { // this field
        type: Object,
        optional: true
    }
}));
Run Code Online (Sandbox Code Playgroud)

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

Ian*_*nes 19

对于您设置的任意子模式的对象 blackbox: true

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

    },
    lastName: {
        type: String,
        optional: true
    },
    twitterFriend: { // this field
        type: Object,
        optional: true,
        blackbox: true
    }
}));
Run Code Online (Sandbox Code Playgroud)

请参阅SimpleSchema 文档以供参考.