7
当我尝试插入某个集合时,在控制台中获取此错误:流星允许Upsert?
“更新失败:访问被拒绝。在限制集合中不允许插入Upsert”。
这里是我指定允许规则:
if (Meteor.isClient) {
Meteor.subscribe('customers');
}
customers = Customers
if (Meteor.isServer) {
Meteor.publish('customers', function() {
return customers.find();
});
customers.allow({
insert: function (document) {
return true;
},
update: function() {
return true;
},
remove: function() {
return true;
}
});
}
这里是UPSERT部分:
Customer.prototype.create = function (name, address, phone, cell, email, website, contact, shipping) {
var attr = {
name : name,
address : address,
phone : phone,
cell : cell,
email : email,
website : website,
contact : contact,
shipping : shipping
};
Customers.upsert(Customers.maybeFindOne(attr)._id, attr);
return new Customer(attr);
};
谢谢!那就是诀窍。我还成功地分解了插入和更新,并使用$ set。 – user3203772