Meteor pagination crashing the browser

I created an infinite scroll pagination in my app using parameter passed sub/pub method and also use limit and skip inside my publications. but when it taking more than 1000 records the app is getting slow and when it comes to 31000 records the app crashing the browser(as per the query, limit is 10 and skip is 0 but the date range will calculate this 31000 records and when i checked my websockets calls i found that this skip and limit not working it takes all records). the total count of the collection
here is my pub/sub code

Meteor.publish(‘posts’, function (fromDate,toDate,limit) {

const user = Meteor.user();

if (!user) throw new Meteor.Error('not-authorized');

return Parcels.find(
    clientId: user.profile.clientId,
      $lte:new Date(toDate),
      $gte:new Date(fromDate)
  fields: {
    postroomBarcode: 0,
    recipientSignature: 0,
    owner: 0,
    deliveredByOwner: 0,
    clientId: 0,
  skip: limit > 10 ? limit - 10 : 0,
  sort: { createdAt: -1 }


const postsSub = Meteor.subscribe(‘posts’,fromDate.get(),toDate.get(),subscriptionLimit.get()).ready();

The publication will keep all the records sent to the client in minimongo. So even you are displaying less with limits, minimongo is still keeping all records in the client

In these cases, we use methods instead of publications

1 Like