我的收藏是否安全?

时间:2016-03-17 16:54:53

标签: meteor meteor-collection2

我从项目中删除了不安全和自动发布的包。但是我将我的集合放在“/ lib”中以供客户端和服务器访问,因为我从客户端插入了值。

当我从控制台输入“db.collectionName.find()。fetch()”时,我可以看到集合中的文档。

有什么方法可以禁用它吗?我知道发布和订阅,但我必须将集合放在服务器端如果没有错,我需要它在“/ lib”,以便我可以插入值。

这是我的收藏:

Products = new Mongo.Collection("products");

Products.attachSchema(new SimpleSchema({
  //collection elements
}));

并允许插入,更新和删除包:

Products.allow({
  insert: function(userId, doc){
    return true;
  },
  update: function(userId, doc, fields, modifier){
    return true;
  },
  remove: function(userId, doc){
    return true;
  }
});

并使用quickForm插入详细信息

{{> quickForm collection="Products" id="submitPostForm"
  type="insert" doc=doc}}

和一个AutoForm.hooks,用于在提交快速表单之前插入我从用户那里获得的URL。它位于“/ client”文件夹

AutoForm.hooks({
    submitPostForm: {  //<--- this is the id of your form
        before: {  //<-- before submit
            insert: function (doc) {  //<-- get the doc to be submitted

                //some values will be inserted in the collection before submitting
            }
        },
        onSuccess: function (formType, result) {

        },
        onError: function (formType, error) {

        }
    }
});

使用模板查找集合中的所有项目以在客户端中列出它们,“因为我想在主页中显示我的集合中的所有文档。”

Template.list_products.helpers({
     applications:function(){
      return Products.find({});
      }
    });

如何不允许用户从控制台获取收集数据?

1 个答案:

答案 0 :(得分:0)

您可以将集合放在/lib中,在/server中发布并在/client中订阅,以便客户端和服务器都知道集合的存在和逻辑,但只知道服务器控制发送的内容。当你说控制台时,你是从终端或网络控制台引用meteor shell吗?

我不认为浏览器控制台可以看到尚未发布的文档,但我不确定allow如何改变它。我个人更喜欢只使用流星方法来改变收藏。

相关问题