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