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

故事扮演 提交于 2019-12-23 21:28:01

问题


trying to read between StackOverflow and the documentation of meteor-simple-schema but can't find a solution. I'trying to insert data in the Meteor.users collection through a form. But keep getting an 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 @ collection2.js:317_.each.Mongo.Collection.(anonymous function) @ collection2.js:154(anonymous function) @ VM47084:2InjectedScript._evaluateOn @ VM47083:883InjectedScript._evaluateAndWrap @ VM47083:816InjectedScript.evaluate @ VM47083:682

Any clue?

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 Schema

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.


回答1:


Try this schema

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 account-password then this schema won't work as that package expect emails to be stored in a certain way.



来源:https://stackoverflow.com/questions/30032315/uncaught-error-when-the-modifier-option-is-true-validation-object-must-have-at

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!