Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing arbitrary object inside a field with meteor simple schema

I have a schema with a field type: Object . But whenever i do an insert, that object is empty.

Here is my schema

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

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

Even if do Contacts.insert({firstName: 'Mustafa', twitterFriend: {test: 'this should be stored'}}) . It does not work.

like image 779
Mustafa Avatar asked Apr 06 '15 02:04

Mustafa


1 Answers

For an object of arbitrary sub-schema you set blackbox: true

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

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

See SimpleSchema docs for reference.

like image 66
Ian Jones Avatar answered Nov 11 '22 08:11

Ian Jones