DP-420 · Question #199
You have an Azure Cosmos DB for NoSQL account that contains a database named DB1. Users run the following query against DB1. SELECT * FROM c WHERE c.bikeParts = "Frame, Chain, Peddles" ORDER BY…
The correct answer is D. ORDER BY c.bikeParts DESC, c._ts ASC. The WHERE clause - c.bikeParts = 'Frame, Chain, Peddles' - filters to records where bikeParts has exactly one distinct value. Because all returned documents share the same bikeParts value, sorting that field ASC or DESC produces an identical result set. This means changing…
Question
You have an Azure Cosmos DB for NoSQL account that contains a database named DB1. Users run the following query against DB1. SELECT * FROM c WHERE c.bikeParts = "Frame, Chain, Peddles" ORDER BY c.bikeParts ASC You add an index to the recordset. You need to change the ORDER BY syntax of the query to optimize the use of the index. The solution must NOT change the result set. Which syntax should you use?
Options
- AORDER BY c._ts ASC, c.bikeParts DESC
- BORDER BY c._ts DESC, c.bikeParts ASC
- CORDER BY c.bikeParts ASC, c._ts ASC
- DORDER BY c.bikeParts DESC, c._ts ASC
How the community answered
(21 responses)- A19% (4)
- B5% (1)
- C5% (1)
- D71% (15)
Explanation
The WHERE clause - c.bikeParts = 'Frame, Chain, Peddles' - filters to records where bikeParts has exactly one distinct value. Because all returned documents share the same bikeParts value, sorting that field ASC or DESC produces an identical result set. This means changing ORDER BY c.bikeParts ASC to ORDER BY c.bikeParts DESC, c._ts ASC (option D) does not alter the visible output. The benefit of option D is index alignment: Azure Cosmos DB composite indexes must exactly match the field order and sort direction declared in the index definition. A composite index defined as (bikeParts DESC, _ts ASC) would be leveraged by this query, turning a full scan into an efficient index seek. Options A and B place _ts first, which breaks the index path for a bikeParts-first filter. Option C (bikeParts ASC, _ts ASC) would match an ASC composite index but is not the answer the exam expects.
Topics
Community Discussion
No community discussion yet for this question.