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

Storing arbitrary object inside a field with meteor simple schema

我有一个包含字段 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'}})。这是行不通的。

对于您设置的任意子模式的对象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