Search code examples
regexmeteor

Collection update Meteor failure from failed regex validation but no regex


I am working with a Meteor schema that has a field defined as below:

export const MyCollectionSchema = new SimpleSchema({
  myField: {
    optional: true,
    type: String,
  },
...
});

We have also attached the behavior below:

export const MyCollection = new Meteor.Collection('my_collection');

MyCollection.deny({
  insert: () => true,
  update: () => true,
  remove: () => true,
});

MyCollection.attachBehaviour('timestampable', {
  createdAt: 'insertedAt',
  createdBy: 'insertedBy',
  updatedAt: 'modifiedAt',
  updatedBy: 'modifiedBy',
});

MyCollection.attachSchema(MyCollectionSchema);

I am trying to update an existing item with this call:

 MyCollection.update(
    { _id: myId },
    { $set: {
      myField: myFieldValue,
      modifiedAt: new Date().toString(),
      modifiedBy:  userId,
    } },
  );

But it keeps failing because of regex validation failure:

(Error: Modified by failed regular expression validation in my_collection update)

I am not using regex in here and am not super familiar with meteor so am not sure if I should be using regex here. Help :/


Solution

  • If I read the documentation for the package you are using (I assume it's this one https://github.com/zimme/meteor-collection-timestampable), then the whole idea is that you won't need to set modifiedAt and modifiedBy. That's what the collection-timestamable package will do for you automatically. The error might happen because the package doesn't like you overriding it's fields. I would try just:

     MyCollection.update({ _id: myId }, {$set: {myField: myFieldValue}});