模拟调用''的效果时出现异常当验证对象包含mongo运算符时,必须将修饰符选项设置为true

Exception while simulating the effect of invoking '' When the validation object contains mongo operators, you must set the modifier option to true

同样的问题还有一个问题,但是我实在是搞不明白

https://forums.meteor.com/t/how-to-fix-error-exception-while-invoking-method-actionfail-error-when-the-validation-object-contains-mongo-operators-you-must-set-the-modifier-option-to-true/53158

有人可以解释一下这个错误吗?

Exception while simulating the effect of invoking '' Error: When the validation object contains mongo operators, you must set the modifier option to true

设置 modifier option to true …如何以及在哪里设置?

谢谢!

这是架构验证的一部分。如果您使用带有验证方法的 simpl-schema 库,并且此架构不是使用 modifier: true 标志创建的,因此它需要一个文档而不是修饰符。

import SimpleSchema from "simpl-schema";

const validationContext = new SimpleSchema({
  name: String,
}).newContext();

validationContext.validate(
  {
    $set: {
      name: 2,
    },
  },
  { modifier: true }
);

console.log(validationContext.isValid());
console.log(validationContext.validationErrors());

参见:https://github.com/longshotlabs/simpl-schema#validate-a-mongodb-modifier