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

CertStreak
Menu

Configure account-level and container-level settings

A worked example

Put in order

You manage the product container in the cosmicworks database of an Azure Cosmos DB for NoSQL account. The container already has one computed property, cp_primaryCategory, which is indexed and used by existing queries.

You must add a computed property named cp_lowerName with the query SELECT VALUE LOWER(c.name) FROM c, and then run this report:

SELECT c.id, c.cp_lowerName FROM c ORDER BY c.cp_lowerName

Requirements:

  • cp_primaryCategory must keep working.
  • You make all changes in Data Explorer in the Azure portal.

Which actions should you perform, in order?

Your order

You didn't answer this one.

Correct order
1In Data Explorer, open the container's Settings, go to Computed Properties, add the cp_lowerName definition to the existing JSON array next to cp_primaryCategory, and select Save.
2In the container's Indexing Policy settings, add { "path": "/cp_lowerName/?" } to includedPaths and select Save.
3Wait for the index transformation that adds /cp_lowerName/? to finish.
4Run the report query that uses ORDER BY c.cp_lowerName.
Why

Save both computed property definitions to preserve cp_primaryCategory. Then explicitly include /cp_lowerName/?, because wildcard indexing does not cover computed properties. Wait for index transformation to finish before running the report, since ORDER BY requires the computed property's index.

  • Step 1: In Data Explorer, open the container's Settings, go to Computed Properties, add the cp_lowerName definition to the existing JSON array next to cp_primaryCategory, and select Save. Define the new property before explicitly indexing its path, and retain the existing definition so that cp_primaryCategory continues working.
  • Step 2: In the container's Indexing Policy settings, add { "path": "/cp_lowerName/?" } to includedPaths and select Save. The definition must exist before its path is explicitly indexed. Computed properties need an explicit included path because the /* wildcard does not cover them.
  • Step 3: Wait for the index transformation that adds /cp_lowerName/? to finish. Saving the policy starts the indexing change; the new index must finish building before the report can use it.
  • Step 4: Run the report query that uses ORDER BY c.cp_lowerName. The completed transformation provides the index required to order results by the computed property.
  • Not needed: Rely on the existing /* included path to index cp_lowerName. The /* wildcard does not cover computed properties, so the ORDER BY query would still fail without an explicit path.
  • Not needed: Replace the existing Computed Properties array entry with the cp_lowerName definition and select Save. Replacing the entry removes the cp_primaryCategory definition required by existing queries.
  • Not needed: Add a spatial index on /cp_lowerName/*. A computed property can't have a spatial index, and a spatial index would not support the report's ORDER BY.

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