Overview of Pagination

Learn how pagination works in Cosmos DB and how to decide between automatic and manual mode.

Introduction

Pagination divides a set of results into pages returned separately. In most cases, Cosmos DB determines when to paginate the results. Let’s start with the only way we can control it. When we query the database, we can use the MaxItemCount option to limit the number of items returned. For example, if the query response contains 100 items, and we set the limit to 20, there will be five pages.

The other causes of pagination are the following:

  • The container doesn’t have enough RUs to fulfill the request.

  • The response is too large.

  • The execution time is too long.

  • The database engine determined that pagination was more efficient.

Automatic handling

Most of the time, we want the SDKs to handle pagination automatically, especially if we don’t specify MaxItemCount. In this case, we need to read the feed until no more results are left.

Get hands-on with 1200+ tech skills courses.