Designing and Implementing Cloud-Native Applications Using Microsoft Azure Cosmos DB — Question 51
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?
Answer options
- A. ORDER BY c._ts ASC, c.bikeParts DESC
- B. ORDER BY c._ts DESC, c.bikeParts ASC
- C. ORDER BY c.bikeParts ASC, c._ts ASC
- D. ORDER BY c.bikeParts DESC, c._ts ASC
Correct answer: D
Explanation
The correct answer is D because it allows for the efficient use of the index by first ordering by c.bikeParts in descending order and then by c._ts in ascending order. This maintains the same result set while optimizing the query execution. The other options either change the order of the results or do not utilize the index effectively.