Ale*_*lex 12 database mongodb node.js meteor
第一个插件工作正常,但第二个插件在控制台中给出"插入失败:403 - 访问被拒绝".自动订阅已启用,我在auth分支上.如何设置我的代码,以便我有一个客户端可以写入的服务器MongoDB?
People = new Meteor.Collection('people');
if (Meteor.is_server) {
People.insert({name: 'Bob'});
}
if (Meteor.is_client) {
People.insert({name: 'Bob'});
}
Run Code Online (Sandbox Code Playgroud)
Ale*_*lex 20
因为您正在使用auth,所以您必须允许或拒绝尝试执行插入,更新,删除和提取的客户端.要解决此特定问题,必须添加Collection.allow()以使客户端的插入工作.
if(Meteor.is_server) {
People.allow({
'insert': function (userId,doc) {
/* user and doc checks ,
return true to allow insert */
return true;
}
});
}
Run Code Online (Sandbox Code Playgroud)
小智 8
在Collection People中使用方法allow().此方法分配访问CRUD.
function adminUser(userId) {
var adminUser = Meteor.users.findOne({username:"admin"});
return (userId && adminUser && userId === adminUser._id);
}
Lugares.allow({
insert: function(userId, lugar){
return adminUser(userId);
},
update: function(userId, lugares, fields, modifier){
return adminUser(userId);
},
remove: function (userId, docs){
return adminUser(userId);
}
});
Run Code Online (Sandbox Code Playgroud)