Error on failure: if the modifier parameter is true, the validation object must have at least one statement

trying to read between StackOverflow and the documentation on the meteor-simple-schema method but can't find a solution. I'm going to insert data into the Meteor.users collection via a form. But keep getting the error:

Uncaught Error: When the modifier option is true, validation object must have at least one operator

      

checkModifier @ simple-schema-validation.js: 271doValidation1 @ simple-schema-validation.js: 321doValidation @ simple-schema-context.js: 9simpleSchemaValidationContextValidate @ simple-schema-context.js: 44doValidate 317 collection2.js:. Mongo (Anonymous function) @ collection2.js: 154 (anonymous function) @ VM47084: 2InjectedScript._evaluateOn @ VM47083: 883InjectedScript._evaluateAndWrap @ VM47083: 816InjectedScript.evaluate @ VM47083: 682

Any hint?

if (Meteor.isClient) {
Template.artistform.events({

    'submit': function (event) {
        event.preventDefault(); //prevent page refresh
        var currentUserId = this.userId;
        form={firstName:firstname.value, lastName:lastname.value};
        Meteor.users.update({_id:currentUserId}, {$set:form});

    }
 });
}

      

And the circuit

Schema = {};

Schema.UserCountry = new SimpleSchema({
name: {
    type: String,
    optional: true
},
code: {
    type: String,
    regEx: /^[A-Z]{2}$/,
    optional:true
}
});

Schema.UserProfile = new SimpleSchema({
firstName: {
    type: String,
    regEx: /^[a-zA-Z-]{2,25}$/,
    optional: true
},
lastName: {
    type: String,
    regEx: /^[a-zA-Z]{2,25}$/,
    optional: true
},
birthday: {
    type: Date,
    optional: true
},
category : {
    type: String,
    allowedValues: ['Painting', 'Music','Other'],
    optional: true
},
 website: {
    type: String,
    regEx: SimpleSchema.RegEx.Url,
    optional: true
 },
 bio: {
    type: String,
    optional: true
 },
country: {
    type: Schema.UserCountry,
    optional: true
}

      

});

Schema.User = new SimpleSchema({
email: {
    type: String,
    optional: true
},
"email.verified": {
    type: Boolean,
    optional: true
},
profile: {
    type: Schema.UserProfile,
    optional: true
},
createdAt: {
    type: Date,
    autoValue: function() {
        if (this.isInsert) {
            return new Date();
        } else if (this.isUpsert) {
            return {$setOnInsert: new Date()};
        } else {
            this.unset();
        }
    }
}
});

Meteor.users.attachSchema(Schema.User);

      

Many thanks.

+3


source to share


1 answer


Try this scheme

Schema.User = new SimpleSchema({
  email: {
    type: Object
  },
  'email.address': {
    type: String,
    optional: true
  },
  "email.verified": {
    type: Boolean,
    optional: true
  },
  profile: {
    type: Schema.UserProfile,
    optional: true
  },
  createdAt: {
    type: Date,
    autoValue: function() {
      if (this.isInsert) {
        return new Date();
      } else if (this.isUpsert) {
        return {$setOnInsert: new Date()};
      } else {
        this.unset();
      }
    }
  }
});

      



Btw if you are using an account password then this scheme will not work as this package expects emails to be stored in a certain way.

+2


source







All Articles