How to filter a query externally and then publish the cursor

I’m trying to publish only documents that a user has access to.
The access system is outside of the document database but a function call like hasAccess(customuserID, _id) will return true if the user has access.

The problem is that publish returns a cursor so I can’t do something like:

Meteor.publish(‘theInvoices’, function () {
  return Invoices.find().fetch().filter(function (doc) {
    return hasAccess(customerUserID, doc._id); // external access , filter

Or course this functions returns an array of filtered documents and not a cursor so the question is how do I filter the results of query (without using database filters) before publishing the results or how do I turn an array of documents into a publishable cursor?


Problem solved via stack overflow using this package

1 Like

Thanks for sharing your solution, @woj! Were you using node-acl for your permissions system? I’m in the process of implementing something similar – were you able to bind permissions info to docs using transforms?