bp123
bp123

Reputation: 3417

Simple schema is accepting null values in required fields

Simple Schema is accepting and inserting null into required fields. Shouldn't it error? Can someone please point out what I'm doing wrong here. I'm using these packages.

Simple Schema

export const ProfileCandidate = new Mongo.Collection('profileCandidate');

const profileCandidate = new SimpleSchema({
  name: Object,
    'name.first': String,
    'name.last': String,
  }
});

Method Call

var data = {
  'name.first': this.state.firstName,
  'name.last': this.state.lastName,
};

insertProfileCandidate.call(data, (err, res) => {
  if(err) {
    console.log("err: ", err);
  }
});

ValidateMethod

export const insertProfileCandidate = new ValidatedMethod({
  name: 'profileCandidate.insert',

  validate: new SimpleSchema({
    'name.first': { type: String, min: 1 },
    'name.last': { type: String, min: 1 },
  }).validator({ clean: true }),

  run(data) {
    ProfileCandidate.insert({
      name: {
        first: data['name.first'],
        last: data['name.last'],
      }
    }, (error, result) => {
      if (error) throw new Meteor.Error('400', error.invalidKeys);
    });
  }
});

Upvotes: 0

Views: 257

Answers (1)

bp123
bp123

Reputation: 3417

OK, it appears as though I needed to also install collection2-core

Upvotes: 1

Related Questions