liveBook · Manning

Collection

As explained in Microsoft Azure in Action

A MongoDB collection is a container that groups related documents for storage and querying.

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

How Microsoft Azure in Action covers it

How deep it goes
Explains creation, shard keys, partitions, throughput, and key-selection trade-offs without detailing MongoDB query syntax.
Examples
Uses an Azure CLI collection command and an Alpaca-Ma-Bags product catalog partitioned by category.
What it assumes
Assumes familiarity with accounts, databases, and documents while defining collections, containers, shard keys, and request units.
What you can do after
Operate collections via Azure CLI by selecting a partition key and configuring request-unit throughput.
How it connects
Connects collections with MongoDB, Cosmos DB, databases, documents, partitioning, shard keys, and request units.

Also explained in

Compare how 16 books explain collection →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microsoft Azure in Action. The section links point to the parts of the book it draws on.