Meteor允许Upsert? [英] Meteor Allow Upsert?
本文介绍了Meteor允许Upsert?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试插入集合时,在控制台中出现此错误:
更新失败:访问被拒绝,限制集合中不允许上载。 p>
这里是我指定的允许规则:
if .isClient){
Meteor.subscribe('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,
联系人:contact,
shipping:shipping
};
Customers.upsert(Customers.maybeFindOne(attr)._ id,attr);
return new Customer(attr);
};
解决方案
这是开发团队的选择。
建议的解决方案是编写一个包装的方法upsert。这使得服务器请求来自服务器代码,而客户端代码仅运行以实现延迟补偿。示例:
//共享代码
Meteor.methods({
customersUpsert:function ){
Customers.upsert(id,doc);
}
});
//从客户端调用
Meteor.call('customersUpsert',Customers.maybeFindOne(attr)._ id,attr);
Getting this error in the console when I try upserting to a collection:
"update failed: Access denied. Upserts not allowed in a restricted collection."
Here are the allow rules I've specified:
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;
}
});
}
Here is the upsert part:
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 );
};
解决方案
This is a choice the development team has made.
The suggested solution is to write a method that wraps upsert. This makes the server request come from server code while the client code only runs for latency compensation. Example:
//shared code
Meteor.methods({
customersUpsert: function( id, doc ){
Customers.upsert( id, doc );
}
});
//called from client
Meteor.call( 'customersUpsert', Customers.maybeFindOne( attr )._id, attr );
这篇关于Meteor允许Upsert?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文