Pagination in MongoDB: Right Way to Do it VS Common Mistakes

Hello fellow community members! :smiley:

I’m excited to share my latest article: Pagination in MongoDB: The Only Right Way to Implement it (Avoid Common Mistakes).

I noticed that many articles, tutorials, and courses do not implement pagination correctly, leading to issues such as data inconsistency and decreased performance. So, in this article I showed how to implement the pagination correctly in MongoDB with the use of Aggregation Framework, as well as how to avoid common mistakes.

I’ve put a lot of effort into creating and I would be thrilled if you could take a look and provide me with any feedback you have. Your input would be greatly appreciated as I am just starting my blog.

Thank you for your time and support!

1 Like

Thanks for sharing.

An alternative way of paging is described at MongoDB Pagination, Fast & Consistent | by Mosius | The Startup | Medium.

1 Like

Hey @steevej,

Thanks for sharing that article. I just checked it. :smiley:

I personally don’t like 2 things from that approach:

  1. You can only fetch the next batch based on current batch, which means you have to start from the first page in order to get the second, and so on. If you want to jump directly to page 5 for example, you can not do it.
  2. Frontend app will not get the total number of items, which is really important for UX in many applications.

I would say that article covers only specific use-case, and not the pagination in general. But it’s definitely a nice solution for the use-case it covers. :smiley:


Your 2 points are valid and something that needs to be considered.

1 Like