Launch price: every exam for $29.99 a year, for the first 300 buyers. See the price

CertStreak
Menu

Implement queries, parameterized queries, paging, and continuation tokens

A worked example

Single answer

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 categoryName value 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?

Choose one answer
Why

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.

Practise this topic until it's automatic.

Ten questions a day, every answer explained, and misses that come back until you beat them.

Start free