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

因为您正在使用身份validation,所以您必须允许或拒绝尝试执行插入,更新,删除和提取的客户端。 若要解决此特定问题,您必须添加Collection.allow()以使客户端的插入工作。

 if(Meteor.is_server) { People.allow({ 'insert': function (userId,doc) { /* user and doc checks , return true to allow insert */ return true; } }); } 

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

我从我的项目中删除不安全的包后遇到了这个错误。

 meteor remove insecure 

以下解决了我的问题。

 Posts = new Meteor.Collection('posts'); Posts.allow({ insert: function(userId, doc) { // only allow posting if you are logged in return !! userId; } }); 

如果您只有简单教程的testing项目,可以通过添加不安全的软件包来解决

 meteor add insecure