Change collection before publishing

I would like to add a property to the objects that are published to the client.

My publish function looks like this:

Meteor.publish("forms", function() {
  return Forms.find();
});

I would like to do something like this

Meteor.publish("forms", function() {
  var forms = Forms.find();
  forms.forEach(function (form) {
     form.nbForms = 12;
  }

  return forms;
});

I want all documents in to formshave a new attribute countthat is sent to the client.

But this clearly does not work.

thank you for your help

+5
source share
2 answers

Not sure if it will work in your case, but you can use the new transform collection function introduced with Meteor 0.5.8

When declaring your collection, add this function as the second parameter:

Forms = new Meteor.Collection("forms", {
     transform: function(f) {
         f.nbForms = 12;
         return f;
     }
});

But it will be both on the server and on the client. I do not know if there is a way to define a conversion function in the context of a publication.

+2
source

, - Meteor : Meteor?

, . Meteor ., , , . , : , ?

+1

All Articles