0

so I'm familiar with Collection.find({}, {limit: someNumber}). Here's my problem:

I have lots of records in Collection that have a createdAt field for sorting. I'm displaying a paginated list of them on the client.

I'm publishing that collection and sorting/limiting the cursor on both server and client. However, what happens is that because the data doesn't get sent in order, the server doesn't actually send the correct items. So if I have 600 records, but only want to see the first 30 initially, I always see 30 list items on screen, but they flicker and change until the client receives all 600 records, at which point it can sort them correctly.

Essentially, Meteor seems to ignore the fact that I want my cursor already sorted on server-side.

What am I doing wrong? How can I make the server only send the first 30 records (they don't need to be sent in order, they just need to be the first 30 according to my sorting rule)

EDIT: Solved it, the problem was in my query, which looked for an empty string in one of the fields, and it confused the server.

1 Answers1

0

You have to sort on the server:

Collection.find({}, {sort: {createdAt: -1}},limit: someNumber);
perusopersonale
  • 896
  • 1
  • 8
  • 18
  • Like I said in the question, I am both sorting and limiting on both server and client. – Jakub Fiala Jul 21 '16 at 17:51
  • If you limit your query, client should not receive all records. So there must be some error in your publication. – perusopersonale Jul 21 '16 at 17:55
  • But what kind of error would this be? the publication just returns the cursor, there's nothing else going on. – Jakub Fiala Jul 21 '16 at 18:17
  • Never mind, solved it, the problem was in my query, which looked for an empty string in one of the fields, and it confused the server. Thanks for your help! – Jakub Fiala Jul 21 '16 at 18:41