草庐IT

javascript - 未捕获错误 : When the modifier option is true, 验证对象必须至少有一个运算符

coder 2023-10-31 原文

尝试在 StackOverflow 和 meteor-simple-schema 文档之间阅读,但找不到解决方案。我正在尝试通过表单在 Meteor.users 集合中插入数据。但是一直报错:

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

有什么线索吗?

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});

    }
 });
}

和架构

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);

非常感谢。

最佳答案

试试这个模式

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();
      }
    }
  }
});

顺便说一句,如果您使用的是帐户密码,那么此架构将无法正常工作,因为该程序包期望电子邮件以某种方式存储。

关于javascript - 未捕获错误 : When the modifier option is true, 验证对象必须至少有一个运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30032315/

有关javascript - 未捕获错误 : When the modifier option is true, 验证对象必须至少有一个运算符的更多相关文章

  1. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  2. ruby-on-rails - 按天对 Mongoid 对象进行分组 - 2

    在控制台中反复尝试之后,我想到了这种方法,可以按发生日期对类似activerecord的(Mongoid)对象进行分组。我不确定这是完成此任务的最佳方法,但它确实有效。有没有人有更好的建议,或者这是一个很好的方法?#eventsisanarrayofactiverecord-likeobjectsthatincludeatimeattributeevents.map{|event|#converteventsarrayintoanarrayofhasheswiththedayofthemonthandtheevent{:number=>event.time.day,:event=>ev

  3. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  4. ruby - 使用 Vim Rails,您可以创建一个新的迁移文件并一次性打开它吗? - 2

    使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta

  5. ruby-on-rails - Rails - 一个 View 中的多个模型 - 2

    我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何

  6. ruby-on-rails - 渲染另一个 Controller 的 View - 2

    我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>

  7. ruby-on-rails - 如何验证非模型(甚至非对象)字段 - 2

    我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss

  8. Ruby 写入和读取对象到文件 - 2

    好的,所以我的目标是轻松地将一些数据保存到磁盘以备后用。您如何简单地写入然后读取一个对象?所以如果我有一个简单的类classCattr_accessor:a,:bdefinitialize(a,b)@a,@b=a,bendend所以如果我从中非常快地制作一个objobj=C.new("foo","bar")#justgaveitsomerandomvalues然后我可以把它变成一个kindaidstring=obj.to_s#whichreturns""我终于可以将此字符串打印到文件或其他内容中。我的问题是,我该如何再次将这个id变回一个对象?我知道我可以自己挑选信息并制作一个接受该信

  9. ruby-on-rails - 如果 Object::try 被发送到一个 nil 对象,为什么它会起作用? - 2

    如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象

  10. ruby - 为什么 SecureRandom.uuid 创建一个唯一的字符串? - 2

    关闭。这个问题需要detailsorclarity.它目前不接受答案。想改进这个问题吗?通过editingthispost添加细节并澄清问题.关闭8年前。Improvethisquestion为什么SecureRandom.uuid创建一个唯一的字符串?SecureRandom.uuid#=>"35cb4e30-54e1-49f9-b5ce-4134799eb2c0"SecureRandom.uuid方法创建的字符串从不重复?

随机推荐