【问题标题】:meteor easy-search server-side filtering流星易搜索服务器端过滤
【发布时间】:2015-11-03 22:47:33
【问题描述】:

我有一个名为“Contacts”的集合,其中每个文档都有 authorId。我希望用户在服务器端搜索集合(出于性能目的,所以我使用 MongoDB 引擎),但只返回与用户具有相同 authorId 的联系人。似乎权限只是允许或拒绝访问整个集合。有没有办法实现服务器端过滤?

谢谢

【问题讨论】:

  • 您是否真的想查询Contacts 的字符串或某个值,然后按userId 过滤,或者您只是想发布所有authorIdMeteor.userId()Contacts
  • 你发布了所有需要的联系人吗?
  • 对不起,我不清楚。我在这里谈论的是easy-search权限:matteodem.github.io/meteor-easy-search/docs/core我不是在谈论流星权限。
  • 另外,这与发布无关,因为我使用的是服务器端搜索。

标签: mongodb search meteor elasticsearch


【解决方案1】:

将 Mongo 选择器添加到查询选项中。

例如:

EasySearch.createSearchIndex('contactsIndex', {
  'collection': Contacts,
  },
  'query': function(searchString) {
     var query = EasySearch.getSearcher(this.use).defaultQuery(this, searchString);
     query.authorId = {$in: Meteor.userId}
     return query;
   }
});

【讨论】:

  • 我有一个简单搜索的示例应用程序。 github.com/DylanKojiCheslin/adamant-octo-kidney
  • 我认为这种方法不安全,因为客户端可以将 Meteor.userId 修改为任何内容并可以访问其他作者的联系人。另外,我使用的是 MongoDB 引擎,因此搜索是在服务器端的整个集合上进行的。
  • Meteor.users.deny({ update: function() { return true; } });
  • Josh Owens 在joshowens.me/… 中推荐了这个
  • 轻松搜索的权限没有服务器限制。您可以让返回权限的函数是 Meteor.method,它使用 joshowens.me/meteor-security-201 的“验证您的用户输入”部分中描述的用户构造模式
【解决方案2】:

我想我找到了使用权限选项的正确方法。

http://matteodem.github.io/meteor-easy-search/docs/core/

基本上,我会将选择器中的 authorId 作为过滤器传递,并在权限中验证 authorId 是否与当前 userId 相同。

我还没有验证权限是否真的在服务器中执行。但是在客户端进行权限检查是非常错误的。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-12
    • 2018-04-15
    • 2015-06-24
    • 2016-09-01
    • 1970-01-01
    • 2018-05-17
    相关资源
    最近更新 更多