0

I have publish code on server-side:

Meteor.publish("getChannelsList", function() {
   return News.find({ }, { title: 1 });
});

And subscriptions.js on client:

Meteor.subscribe("getChannelsList", function(err, res) {
  if (err) {
    throw new Meteor.Error("Subscription error", "Exception in Meteor.subscribe method", err);
  }
  return res;
});

Collection in it's own "collections" directory

News = new Meteor.Collection("newsStock");

This is my template helper:

Template.channel.helpers({
    channels: function() {
        return News.find({ }, { title: 1 });
    }
});

Autopublish and insecure were removed. I'm waiting on client database object with "title" and "id" only. If I do in browser debugger News.find().pretty() why I see whole object, with all fields? Removing autopublish is not affect for me.

Can I do multiple publications and subscribes and how it's works?

j0k
  • 22,600
  • 28
  • 79
  • 90
dvplut
  • 323
  • 2
  • 4
  • 12
  • I wrote a well-received post about multiple publications at [Understanding Meteor Publish/Subscribe](http://stackoverflow.com/questions/19826804/understanding-meteor-publish-subscribe/21853298#21853298). Hope it helps! – Dan Dascalescu Feb 21 '15 at 13:08

1 Answers1

0

If you're only intending to return the title, it should be:

Template.channel.helpers({
    channels: function() {
        return News.find({ }, {
            fields: {
                title: 1 
            }
        });
    }
});

As you point out, this will also publish the _id by default.

richsilv
  • 7,993
  • 1
  • 23
  • 29
  • Yes, this work for me. Thank you. With my small experience in Mongo and Meteor can I ask one more question? Why if I execute in Mongo shell db.newsStock.find({}, {fields: {title: 1}}).pretty() Mongo throw error, but db.newsStock.find({}, {title: 1}).pretty() work well. Meteor Mongo and Mongo not equal? – dvplut Nov 25 '14 at 10:02
  • Correct, the APIs are not equivalent, particularly when it comes to sorting, skipping and limiting. Meteor find API is [well-documented](http://docs.meteor.com/#/full/find), and I would always refer to the docs rather than relying on Mongo experience. – richsilv Nov 25 '14 at 10:05