Storing arbitrary object inside a field with meteor simple schema
Asked Answered
H

1

12

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.

Hurd answered 6/4, 2015 at 2:1 Comment(0)
T
21

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.

Tryparsamide answered 6/4, 2015 at 4:29 Comment(2)
this doesn't seem to work at all, it's like SimpleSchema just ignores blackbox?Paralytic
@Paralytic You might have to post your code in another question, then link us to it. Maybe something else is slightly off?Tryparsamide

© 2022 - 2024 — McMap. All rights reserved.