我使用的Meteor模式有一个定义如下的字段:
export const MyCollectionSchema = new SimpleSchema({
myField: {
optional: true,
type: String,
},
...
});
我们还附上了以下行为:
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);
我正在尝试使用此调用更新现有项目:
MyCollection.update(
{ _id: myId },
{ $set: {
myField: myFieldValue,
modifiedAt: new Date().toString(),
modifiedBy: userId,
} },
);
但由于regex验证失败,它一直失败:
(错误:由my_collection更新中失败的正则表达式验证修改(
我在这里没有使用regex,也不太熟悉流星,所以不确定我是否应该在这里使用regex。帮助:/
如果我阅读了您正在使用的包的文档(我认为是这个https://github.com/zimme/meteor-collection-timestampable),那么整个想法就是不需要设置modifiedAt
和modifiedBy
。这就是collection-timestamable
软件包将自动为您提供的功能。发生此错误的原因可能是程序包不希望您覆盖它的字段。我会试试:
MyCollection.update({ _id: myId }, {$set: {myField: myFieldValue}});