javascript - Join in Meteor with publishComposite -


i have removed autopublish meteor app. i'm publishing collections manually. have related collections. want increase performance as possible.

if i'm, instance, looking @ post , want see comments related post, have query database both post: posts.findone(postid) , comments: comments.find({postid: postid}). querying 2 collections in data field iron-router present in template i'm subscribing publications in waiton. have found https://github.com/englue/meteor-publish-composite lets me publish multiple collections @ same time. don't quite understand it. if i'm using meteor.publishcomposite('postandcomments', ...) in server/publish.js, subscribing postandcomments in waiton, , setting both post , comments in data do, have saved demand on database? me looks still query database same number of times. queries done when publishing queries made while queries done data way retrieve has been queried database?

besides, in example 1, shown how publish top posts belonging comments , post/comment authors, in template, posts outputted. how can output comments , authors? have misunderstood potentials of publishcomments? understand kind of join.

i used publishcomposite successfully. in example below i'm subscribing units matching filter properties units belong to.

meteor.publishcomposite('unitswithproperties', function (filter) {     var filter = filter || {};     console.log(filter);     return {         find: function () {             var units;             units = units.find(filter);             return units;         },         children: [             {                 collectionname: 'properties',                 find: function (unit) {                     return properties.find({ _id: unit.propertyid });                 }             }         ]     }; }); 

in case believe can:

  • subscribe posts matching topposts criteria
  • subscribe comments , authors of posts in children: array of cursors

.

hope helps.

alex


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -