gpt4 book ai didi

collections - meteor 允许更新?

转载 作者:行者123 更新时间:2023-12-04 11:25:00 25 4
gpt4 key购买 nike

当我尝试升级到一个集合时,在控制台中出现此错误:

“更新失败:访问被拒绝。在受限集合中不允许更新。”

以下是我指定的允许规则:

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 );
};

最佳答案

这是 a choice the development team造成。

建议的解决方案是编写一个包装 upsert 的方法。这使得服务器请求来自服务器代码,而客户端代码仅用于延迟补偿。例子:

//shared code
Meteor.methods({
customersUpsert: function( id, doc ){
Customers.upsert( id, doc );
}
});

//called from client
Meteor.call( 'customersUpsert', Customers.maybeFindOne( attr )._id, attr );

关于collections - meteor 允许更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21178078/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com