[Solved] Understanding {{#each}}

I’m having a little trouble understanding what is happening in Meteor with regard to how meteor updates {{#each}}. I’m going through a tutorial and when run a find() the results returned are as expected but {{#each}} doesn’t update the view the way I expect when the number of items is limited.
If I insert and then run the find() shouldn’t all of the items inside {{#each}} be re-rendered in the view?

Could you post the #each block and the helper that is supplying the cursor/array?

It’s kinda hard to trouble shoot this without any code. Can you post some code or link to a repo?

Sure. Basically this is the Leaderboard tutorial from MeteorTips. I’ve went through the tutorial as it was presented, and now I’m just trying to modify things to see how they work. I’m total newb here.


'dailyLog': function(){
  return WeighIn.find({}, {sort:{date: 1}, limit:5});


'dailyLog': function(){
  return WeighIn.find({}, {sort:{date: 1}, limit:5});

Basically, I’m returning 5 items, when I insert a 6th, I’d like the view to update to 2,3,4,5,6, but the table doesn’t remove the 1st item and roll the data up to display 2,3,4,5,6 unless I manually remove something. I’m under the impression the find() helper was automatically run on every insert. I’m a new user so I can’t upload the screenshot of my table.

<table class="table table-bordered table-hover table-striped">
Date Weight BodyFat
{{#each dailyLog}}
  <td class="logdata {{selectedClass}}">{{date}}</td>
  <td class="logdata {{selectedClass}}">{{weight}}</td>
  <td class="logdata {{selectedClass}}">{{bodyfat}}</td>

I believe the problem is your query sort. Try -1 instead of 1

I’ve tried that Here’s the github, if you’d like to take a look: https://github.com/aaronspe/ChubTrak.git

Just add 5 items, you’ll see they get added to the table view. Then add the 6th. Instead removing item 1 and shifting everything up, it stays like it is. If you remove an item, then things will shift.

Well, I thought I figured it out, but even my fix doesn’t work. So limit is the number of loops displayed but has no bearing on what documents it uses, even if you sort differently? How do you update what records are pulled in for display? Or is my insert statement wrong? The console just keep showing it adding objects.

[Solved] sorta
This ended up doing what I want, but now the reverse of this doesn’t do what I want so… whatever. Maybe this post will help someone in the future. How to sort and show in unnatural(?) sort order with a limit:

return WeighIn.find({}, {sort:{weight: -1}, limit:5}).fetch().reverse();

Are you using autopublish? Is every document from the WeighIn collection getting published to the client? In the console, type WeighIn.find().fetch() and see how many objects get returned.

My thinking is that if you aren’t using Autopublish and have your own pub/sub set up, you aren’t correctly sorting/limiting on the server side.