I have a collection called "Articles". Each article has a category. I would like to have a global variable being an array with each distinct category value in my Articles collection.
I tried to do it this way:
/models/article.coffee:
@Articles = new Meteor.Collection "articles"
Articles.categories = ->
  Meteor.call "articleCategories", (e, r) ->
    unless e
      return r
/server/article_server.coffee:
Meteor.methods
  articleCategories: ->
    categories = _.uniq(Articles.find({}, {sort: {category: 1}, fields:
        {category: true}}).fetch().map (x) ->
        x.category
    , true)
    return categories
This doesn't work. The result is "undefined" when I call Articles.categories() from the console.
What am I doing wrong?
EDIT:
I want to do this because I want my article categories to be available everywhere in the website.
As Articles collection will not be published on every pages, I tought, I could just generate an array server side and pass it over to the client.
But maybe it's not a good idea...
 
     
     
    