0

Let's say, we have this schema :

Schemas.MyCollection = new SimpleSchema({
    something: {
        type: Object
    }
});

I want to insert something into MyCollection. For example :

var myobj = {
    aaaaaa: 11111,
    bbbbbb: 22222
};
MyCollection.insert({something: myobj});

We end up with this :

{
    _id: "someId",
    something: {}
}

When I disable simple schema checking (collection2), everything works as one expected.

Simple-schema did not report an error (collection2) so why it is invalid?

Kyll
  • 7,036
  • 7
  • 41
  • 64
dev1223
  • 1,148
  • 13
  • 28
  • 2
    Please avoid swear words. – Kyll Sep 25 '15 at 12:19
  • You will say the same after some hours of wastefull work thanks to genial library ... – dev1223 Sep 25 '15 at 12:21
  • 1
    I don't care. Your question was full of useless fluff that made reading it painful. You are angry, we get it, but please stay professional around here. – Kyll Sep 25 '15 at 12:24

2 Answers2

4

@Seraph your schema is wrong

Schemas.MyCollection = new SimpleSchema({
    something: {
        type: Object
    },

    'something.aaaaa': {
      type: String
    }
});

and so on you have to write every property the object has or you can do blackbox: true if you don't want to validate the object:

something: {
  type: Object,
  blackbox: true
}

Also if it's server-side operation you can do myCollection.insert(doc, {validate: false});

just read the docs https://atmospherejs.com/aldeed/collection2 :)

0

Here is the reference to help you understand more:

https://github.com/aldeed/meteor-simple-schema#blackbox

Lingxiao Sun
  • 111
  • 7