0

I am trying to validate an object using SimpleSchema in Meteor, before inserting it into the database.

The object looks like this, as I print it from the Meteor method that calls the insert:

channels: { '1': [ 'rect4557-6-4-5-7-4-2', 'rect4557-6-4-97-0-7-6-3' ] } }

If I insert it in the database without attaching a schema to it, it works fine. However, when I have it run through SimpleSchema, the field value as outputted from console.log in the custom validation method is an empty object {}. Even if I don't run any validation, an empty object is stored if SimpleSchema is used.

Code to produce the simpleschema value output:

Arch.schema = new SimpleSchema({   
    channels: {
    type: Object,
    custom: function validateChannels() {
      console.log("this.value:", this.value)
    } 
}); 
Architectures.attachSchema(Architectures.schema);

Really, what should I do? Is this a bug in SimpleSchema?

2
  • Please show your simple-schema code. Commented Oct 18, 2016 at 19:36
  • thank you @MichelFloyd, added some code Commented Oct 18, 2016 at 19:49

1 Answer 1

2

It looks like you just need to add blackbox: true option. SimpleSchema does not support arbitrary object keys unless you mark it as a blackbox object. See https://github.com/aldeed/meteor-simple-schema#blackbox

The filtering, which is part of the automatic cleaning, is what strips this out for you. If you want to prevent that in a specific insert call, just pass filter: false option. See https://github.com/aldeed/meteor-collection2#skip-removing-properties-that-are-not-in-the-schema

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.