A question concerning using the limit parameter for messages

Hello everyone, this is a very basic question which I haven’t been able to find any discussion on.

For me, the expected behavior of a chat application is to load some ammount of messages from the database initially, and then show all new messages that appear. Maybe I initially load only the latest 10 messages (by sorting on the date and setting initial limit of 10 in the publication function),
and then implement infinite scrolling to fetch older messages.

This would result in this behavior: Some user logs in, sees the 10 newest messages from the db (call them A). Newer messages (B) start to arrive.Now the messages A would start to dissapear (because we set limit to 10).

How would you solve this issue? I see one basic solution, which is to have two different pubs/subs, one set up for receiving new messages and one for paginating the chat history. Another solution is to increment the limit when a new message appears on the client.

Am I missing something ? Does anyone else recognize this as a common thing to address with meteor?

Best regards

Two pub/subs is a good approach. The first is the most recent 10, the second is all posts newer than “now”. Meteor’s “mergebox” ensures that your client-side minimongo collection contains a single, merged set of documents.

Thank you for the reply! I had implemented a solution that works like this. Am not sure if starting additional pub/subs has some implications for performance, but I think I will keep using this setup for now.