How to find out what documents are sent to the client in the meteor

I have a publication that sends a limited number of entries based on startandlimit

Metero.publish("posts",function(start,limit){
 return Posts.find({},{"start":start,"limit":limit});
});

I subscribe to a publish function in a function autorun.

My problem: I already have several collection entries postson the client that is being used by another table

the current publish function may have entries that already exist in the client

I just want to know the records sent by the current publish function.

Any hacks or work around are also welcome.

EDIT I want to display those records that are published in the table, since I already have some data on the client. It is very difficult to filter which records are sent to the client by the publish function

+1
source share
3 answers

I ended up using "client-side collections" with custom publications for different tables

-1
source

Try this publish feature,

Meteor.publish('posts', function(limit) {
  if (limit > Posts.find().count()) {
    limit = 0;
  }

  return Posts.find({ },{limit:limit});
});

now on client.js

Template.Posts.created = function() {
  Session.setDefault('limit', 10);
  Tracker.autorun(function() {

    Meteor.subscribe('getPosts', Session.get('limit'));
  });
}

now you can use this helper,

Template.Posts.helpers({
  posts: function() {
    return Posts.find({ }, { limit: Session.get('limit') });
  }
});

and using it like any normal assistant on each of the assistants

<template name="Posts">
{{#each posts}}
{{namePost}} <!-- or whatever register on the posts mongo document -->
{{/each}}
<!-- button to load more posts -->
<button class="give-me-more">Click for more posts </button>
</template>

now if you want to increase the number of posts by 10 x 10 use this function

incrementLimit = function(inc=10) {
  newLimit = Session.get('limit') + inc;
  Session.set('limit', newLimit);
}

and call it a click event like this

Template.Posts.events({
  'click .give-me-more': function(evt) {
    incrementLimit();
  }
});

Now every time the created message template is created, you will receive only 10 messages on each template that you use this helper, and download 10 times each button by pressing the button

This is the same code from Gentlenode

HTML, ,

+2

Have you considered logging on the console?

Metero.publish("posts",function(start,limit){
 var currentPosts = Posts.find({},{"start":start,"limit":limit});
 console.log(currentPosts);
 return currentPosts;
});
0
source

Source: https://habr.com/ru/post/1569760/


All Articles