title: Filter subscription bases on user roles in Meteor
body: <p>I am using <a href="https://github.com/alanning/meteor-roles" rel="nofollow noreferrer">meteor-roles</a> package for adding roles functionality to the app. Now I'm trying to filter a subscription of product based on the user of having a role to see that product category.</p>
  
  <p>I thought I can use <a href="https://stackoverflow.com/questions/24364886/where-mongo-operator-work-around-in-meteorjs">mongo $where in meteor</a> but I can specify the $where function only as serialized string which does not have access to the roles package.</p>
  
  <p>Example of adding a user to a role for viewing specific category. </p>
  
  <pre><code>Roles.addUsersToRoles(userIdA, 'view-product-category', 'product-category-a');
  </code></pre>
  
  <p>Current code that does not work. <code>userId</code> does not exists when the function get deserialized in mongo engine. </p>
  
  <pre><code>Meteor.publish('products', function () {
    let userId = this.userId;
  
    let query = {
      $where: function () {
        return Roles.userIsInRole(userId, 'view-product-category', `product-catogory-${this.category}`);
      }.toString();
    };
  
    return Products.find(query);
  });
  </code></pre>
  
  <p>How does one filter a collection based on values different collection, which what I'm trying to do here ?</p>
  
  <p>Current direction is to serialize the function myself and put the values needed there. I'm looking to know if there is more general and robust way of doing this kind of acl access filtering on subscriptions. </p>