A MongoDB collection groups related documents. In Azure Cosmos DB for MongoDB, the collection acts as the container inside a database, which belongs to an account. section 11.1
When creating a collection, choose the settings that shape distribution and capacity:
- Set a shard, or partition key, such as /category, to distribute documents across partitions. section 11.1 section 11.3.2
- Choose a high-cardinality, immutable key that matches access patterns and helps avoid oversized partitions. section 11.3.2
- Set throughput in request units per second (RU/s); reads, writes, and queries consume units according to their complexity. section 11.1
Product catalog collection
For a catalog whose sales are evenly spread across product categories, create alpacacontainer with /category as its shard key and 400 RU/s. Product documents can contain id, name, category, region, price, and inventory. section 11.3.2
C:/> az cosmosdb mongodb collection create --account-name alpacacosmosdbaccount --database-name alpacacosmosdb --name alpacacontainer --resource-group AlpacaRG --shard "/category" --throughput 400
See the Azure CLI command that creates a MongoDB collection with /category as its shard key and 400 RU/s of throughput. section 11.3.2















