Real key-based CosmosDB Pagination with .NET Core

Recently I had to implement a pagination mechanism for usage with Azure CosmosDB and Azure Functions on .NET Core 3.1.
After stumbling upon several issues like f.e.:

  • Partition key ranges were not taken into respect
  • Pagination links were hard to setup
  • URL Encoding continuation tokens
  • Parsing URL query parameters into SqlQuerySpec

I’ve published following repository on GitHub:

DSpirit/azure-functions-cosmosdb-pagination: C# Azure Function App .NET Core 3.1 – CosmosDB Queries with Pagination (github.com)

The function is setup in C# using .NET Core 3.1 on Azure Function Apps.

An example call could look as follows:

GET http://localhost:7071/api/storage/collection?q={ "QueryText": "SELECT * FROM c", "Parameters": [] }&pageSize=2

Leave a Reply

Your email address will not be published.