在Meteor中,我什么时候应该 Select method而不是deny
规则?
在我看来,应该支持allow
/deny
规则,因为它们的目标更明确,而且人们知道在哪里可以找到它们.
然而,在《发现Meteor 》一书中,防止重复插入("重复"被定义为添加一个文档,其url
属性已经在同一集合的其他文档中定义)必须通过一种方法来定义(并留给读者作为练习,第8.3章).
我认为我能够以一种更清晰的方式实施这项判断:
Posts.deny({
update: function(userId, post, fieldNames, modifier) {
return Posts.findOne({ url: modifier.$set.url, _id: { $ne: post._id } });
}
});
(N.B. if you know the example, yes, I voluntarily left out the “only a subset of the attributes is modified” check from the question to be more specific.)
我知道Mongo还有update operators个而不是$set
个,但它们看起来像是打印出来的,我不想留下一个安全漏洞.
那么:我的deny
条规则有什么缺陷吗?独立而言,我应该 Select 一种方法吗?我能从中得到什么?我会失go 什么?