Table: azure_cosmosdb_mongo_collection - Query Azure Cosmos DB Mongo Collections using SQL
Azure Cosmos DB is a globally distributed, multi-model database service for any scale. It offers multiple well-defined consistency models, guaranteed single-digit-millisecond read and write latencies at the 99th percentile, and guaranteed 99.999% high availability with multi-homing. In particular, the Mongo Collection is a resource within the Azure Cosmos DB that represents a group of MongoDB documents.
Table Usage Guide
The azure_cosmosdb_mongo_collection
table provides insights into Mongo Collections within Azure Cosmos DB. As a database administrator, explore collection-specific details through this table, including the collection's name, resource group, account name, and more. Utilize it to uncover information about collections, such as their properties, the associated database, and the verification of their configurations.
Important notes:
- You must specify the
database_name = '<cosmosdb_mongo_database_name>'
in thewhere
clause to query this table.
Examples
Basic info
This query is used to gain insights into the relationship between Azure CosmosDB Mongo collections and databases. It can be used to manage and analyze the distribution of resources across different databases and regions, which is crucial for optimizing resource usage and performance.
select c.name, c.database_name, c.account_name, c.region, c.resource_group, c.shard_key, c.idfrom azure_cosmosdb_mongo_collection c, azure_cosmosdb_mongo_database dwhere c.database_name = d.name;
select c.name, c.database_name, c.account_name, c.region, c.resource_group, c.shard_key, c.idfrom azure_cosmosdb_mongo_collection c, azure_cosmosdb_mongo_database dwhere c.database_name = d.name;
Collection count by cosmos DB database name
Discover the segments that have a significant number of collections in your Azure Cosmos DB. This is beneficial for understanding database usage and managing resource allocation effectively.
select c.database_name, count(c.name) as collection_countfrom azure_cosmosdb_mongo_collection c, azure_cosmosdb_mongo_database dwhere c.database_name = d.namegroup by database_name;
select c.database_name, count(c.name) as collection_countfrom azure_cosmosdb_mongo_collection c join azure_cosmosdb_mongo_database d on c.database_name = d.namegroup by c.database_name;
Get throughput settings for each collection
Analyze the settings to understand the throughput configurations for each collection in your Azure Cosmos DB. This helps in optimizing resource utilization and managing the performance of your database.
select c.name as collection_name, c.database_name, c.account_name, c.throughput_settings ->> 'Name' as name, c.throughput_settings ->> 'ResourceThroughput' as throughput, c.throughput_settings ->> 'AutoscaleSettingsMaxThroughput' as maximum_throughput, c.throughput_settings ->> 'ResourceMinimumThroughput' as minimum_throughput, c.throughput_settings ->> 'ID' as idfrom azure_cosmosdb_mongo_collection c, azure_cosmosdb_mongo_database dwhere c.database_name = d.name;
select c.name as collection_name, c.database_name, c.account_name, json_extract(c.throughput_settings, '$.Name') as name, json_extract(c.throughput_settings, '$.ResourceThroughput') as throughput, json_extract( c.throughput_settings, '$.AutoscaleSettingsMaxThroughput' ) as maximum_throughput, json_extract( c.throughput_settings, '$.ResourceMinimumThroughput' ) as minimum_throughput, json_extract(c.throughput_settings, '$.ID') as idfrom azure_cosmosdb_mongo_collection c, azure_cosmosdb_mongo_database dwhere c.database_name = d.name;
Get index keys in each collection
Determine the areas in which specific index keys are used across different collections in Azure Cosmos DB. This is beneficial for optimizing database performance and understanding data distribution across your collections.
select c.name as collection_name, c.database_name, c.account_name, i -> 'key' -> 'keys' as index_keysfrom azure_cosmosdb_mongo_collection c, azure_cosmosdb_mongo_database d, jsonb_array_elements(indexes) iwhere c.database_name = d.name;
select c.name as collection_name, c.database_name, c.account_name, json_extract(i.value, '$.key.keys') as index_keysfrom azure_cosmosdb_mongo_collection c, azure_cosmosdb_mongo_database d, json_each(indexes) as iwhere c.database_name = d.name;
Query examples
Schema for azure_cosmosdb_mongo_collection
Name | Type | Operators | Description |
---|---|---|---|
_ctx | jsonb | Steampipe context in JSON form. | |
account_name | text | = | The friendly name that identifies the cosmosdb account in which the collection is created. |
akas | jsonb | Array of globally unique identifier strings (also known as) for the resource. | |
analytical_storage_ttl | bigint | Analytical TTL. | |
autoscale_settings_max_throughput | bigint | Contains maximum throughput, the resource can scale up to. | |
cloud_environment | text | The Azure Cloud Environment. | |
collection_etag | text | A system generated property representing the resource etag required for optimistic concurrency control. | |
collection_id | text | Name of the Cosmos DB MongoDB collection. | |
collection_rid | text | A system generated unique identifier for collection. | |
collection_ts | bigint | A system generated property that denotes the last updated timestamp of the resource. | |
database_name | text | = | The friendly name that identifies the database in which the collection is created. |
id | text | Contains ID to identify a Mongo DB collection uniquely. | |
indexes | jsonb | List of index keys. | |
name | text | = | The friendly name that identifies the Mongo DB collection. |
region | text | The Azure region/location in which the resource is located. | |
resource_group | text | = | The resource group which holds this resource. |
shard_key | jsonb | A key-value pair of shard keys to be applied for the request. | |
sp_connection_name | text | =, !=, ~~, ~~*, !~~, !~~* | Steampipe connection name. |
sp_ctx | jsonb | Steampipe context in JSON form. | |
subscription_id | text | =, !=, ~~, ~~*, !~~, !~~* | The Azure Subscription ID in which the resource is located. |
tags | jsonb | A map of tags for the resource. | |
throughput | bigint | Contains the value of the Cosmos DB resource throughput. | |
throughput_settings | jsonb | Contains the Cosmos DB resource throughput or autoscaleSettings. | |
title | text | Title of the resource. | |
type | text | Type of the resource. |
Export
This table is available as a standalone Exporter CLI. Steampipe exporters are stand-alone binaries that allow you to extract data using Steampipe plugins without a database.
You can download the tarball for your platform from the Releases page, but it is simplest to install them with the steampipe_export_installer.sh
script:
/bin/sh -c "$(curl -fsSL https://steampipe.io/install/export.sh)" -- azure
You can pass the configuration to the command with the --config
argument:
steampipe_export_azure --config '<your_config>' azure_cosmosdb_mongo_collection