How to subscribe to rawCollection?


#1

I have “Categories” collection on the server and the client,
I have this pub on the server:

Meteor.publish('categories', function() {
    return Categories.rawCollection().distinct('category');
});

and I have this sub on the client:

this.subscribe('categories');
let categories = Categories.find()

I think it should work, but it doesn’t.
so what is wrong with this code?


#2

The issue here is that the rawCollection methods are not wrapped with Futures into synchronous style. What you need to do is something like:

const raw = Categories.rawCollection();
const distinct = Meteor.wrapAsync(raw.distinct, raw);

Meteor.publish('categories', function() {
    return distinct('category');
});