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

There is another question about the same issue, but I really couldn’t get it.

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

Could someone explain a little more about this error?

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

Set modifier option to true … how and where that would be?

Thank you!



Solution 1:[1]

This is part of the schema validation. Somehwere you use a simpl-schema library with a validation method and this schema is not created with the modifier: true flag, so it's expecting a document and not a modifier.

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

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jankapunkt