A .NET API uses the Azure Cosmos DB for NoSQL .NET SDK to query a product container partitioned on /categoryId. Each product has a categoryName string property. A new endpoint returns a category filter list built from all products, with these requirements:
- The response body is a JSON array of plain strings, such as
["Bikes, Touring Bikes", "Clothing, Vests"]. - Each
categoryNamevalue appears only once in the full result. - Clients page through the list across separate HTTP requests by sending back a continuation token.
Which query should the endpoint run?
The endpoint needs scalar strings, no duplicates, and resumable paging. VALUE turns a single-property projection into plain strings and DISTINCT removes repeated names. Adding ORDER BY is what allows a DISTINCT query to return continuation tokens; without it, the query cannot be resumed. Only the DISTINCT VALUE query with ORDER BY meets all three requirements in the .NET SDK.
- Not correct:
SELECT VALUE p.categoryName FROM product p ORDER BY p.categoryName. Without DISTINCT, the query returns one value per product, so category names repeat for every product in the category. - Not correct:
SELECT DISTINCT VALUE p.categoryName FROM product p. A DISTINCT query without ORDER BY cannot use continuation tokens, so clients could not resume it across requests. - Correct:
SELECT DISTINCT VALUE p.categoryName FROM product p ORDER BY p.categoryName. VALUE returns plain strings, DISTINCT removes duplicates, and adding ORDER BY to a DISTINCT query lets it use continuation tokens. - Not correct:
SELECT DISTINCT p.categoryName FROM product p ORDER BY p.categoryName. Without VALUE, the query returns single-property objects rather than an array of scalar strings.