A cross-partition query retrieves data from multiple logical partitions. In Azure Cosmos DB, that broader search can increase request-unit charges and latency, so partition-key design matters before the query ever runs. section 11.3.3 section 11.3.2
Reduce the number of partitions a query must visit by:
- Filtering common queries on the partition key; a products-by-region query can use region to narrow its work. section 11.3.3
- Combining frequently queried attributes in a composite partition key, such as region-category. section 11.3.3
- Using a time-based component, such as region-date, when access patterns follow time. section 11.3.3
Alpaca-Ma-Bags product search
If products are commonly retrieved by region, choosing region as the partition key helps avoid broad queries. If region and category are usually queried together, a composite region-category key can narrow access further. section 11.3.3
C:/> az cosmosdb mongodb collection create --account-name alpacacosmosdbaccount --database-name alpacacosmosdb --name alpacacontainer --resource-group AlpacaRG --shard "/region-category" --throughput 400
The collection configuration shows a composite /region-category shard, a concrete way to align storage with related query attributes. section 11.3.3
