Complete reference for all Cosmos Shell commands.
Connect to a Cosmos DB endpoint.
Usage: connect [-hint <ARG>] connectionString
Arguments:
connectionString The account connection string or endpoint URL
Options:
-hint Pre-populates the username for Azure AD login
Examples:
# Connect using endpoint (Azure AD auth)
connect "https://myaccount.documents.azure.com:443/"
# Connect with username hint
connect -hint "[email protected]" "https://myaccount.documents.azure.com:443/"Alternative connect command using Azure authentication.
Usage: azconnect endpoint
Arguments:
endpoint The account endpoint or connection string
Disconnect from the current account.
Usage: disconnect
Change scope to a database or container.
Usage: cd [item]
Arguments:
[item] The database or container to select (optional)
Behavior by context:
- From connected state:
cd <database>enters that database - From database:
cd <container>enters that container cd ..goes up one levelcd(no argument) returns to connected state- Supports chaining:
cd dbName/containerName
Examples:
# Enter a database
cd myDatabase
# Enter a container
cd myContainer
# Chain navigation
cd myDatabase/myContainer
# Go up one level
cd ..
# Switch containers quickly
cd ../otherContainer
# Return to connected state
cdList resources at the current scope.
Usage: ls [-m <ARG>] [filter]
Arguments:
[filter] Filter pattern (optional)
Options:
-max, -m Maximum number of items to return
Behavior by context:
- Connected state: Lists databases
- In database: Lists containers
- In container: Lists items (documents)
Examples:
# List all databases
ls
# List with limit
ls -m 10
# Filter results
ls "user*"Create a new database.
Usage: mkdb name
Arguments:
name The database name to create
Example:
mkdb myNewDatabaseCreate a new container in the current database.
Usage: mkcon name partition_key
Arguments:
name The container name
partition_key The partition key path
Example:
cd myDatabase
mkcon users /userIdCreate items in the current container. Reads JSON from the pipeline.
Usage: mkitem
Examples:
# Create a single item
echo '{"id":"1","pk":"a","name":"Item 1"}' | mkitem
# Create multiple items
echo '[{"id":"1","pk":"a"},{"id":"2","pk":"b"}]' | mkitemGeneric create command for items, containers, or databases.
Usage: create item [name] [partition_key]
Arguments:
item Object type: item, container, or database
[name] Container or database name (optional)
[partition_key] Partition key for container (optional)
Remove items from the current container.
Usage: rm pattern
Arguments:
pattern Pattern for items to remove
Example:
rm item123Remove a container.
Usage: rmcon name
Arguments:
name The container to remove
Example:
rmcon oldContainerRemove a database.
Usage: rmdb name
Arguments:
name The database to remove
Example:
rmdb oldDatabaseGeneric delete command.
Usage: delete item pattern
Arguments:
item Object type: item, container, or database
pattern The items/container/database to delete
Execute a SQL query and return results.
Usage: query [-m <ARG>] query
Arguments:
query The SQL query to execute
Options:
-max, -m Maximum number of items to return
Examples:
# Basic query
query "SELECT * FROM c"
# Query with filter
query "SELECT * FROM c WHERE c.status = 'active'"
# Limit results
query -m 10 "SELECT * FROM c ORDER BY c._ts DESC"
# Query specific fields
query "SELECT c.id, c.name FROM c WHERE c.type = 'user'"Print a specific item by ID and partition key.
Usage: print id key
Arguments:
id The ID of the item
key The partition key value
Example:
print user123 "partition-a"Print a message or pipe JSON to other commands.
Usage: echo message
Arguments:
message The message or JSON to print
Examples:
# Print a message
echo "Hello, Cosmos!"
# Create JSON for piping
echo '{"id":"1","pk":"a"}' | mkitem
# Print from pipeline
ls | echo $.items[0]Display the contents of a file.
Usage: cat [path]
Arguments:
[path] The file path to display (optional)
Show account overview or container settings.
Usage: settings
Behavior:
- Connected/database state: Shows account overview
- Container state: Shows container settings
Get or set the SDK throughput bucket.
Usage: bucket [bucket]
Arguments:
[bucket] Bucket number (0 clears; valid: 1-5) (optional)
Show help for commands.
Usage: help [-details] [command]
Arguments:
[command] Specific command to get help for (optional)
Options:
-details, -d Show detailed help for all commands
Examples:
# List all commands
help
# Get help for specific command
help query
# Show detailed help for all commands
help -detailsExit the Cosmos Shell.
Usage: exit
Execute Azure CLI commands.
Usage: az [args]
Arguments:
[args] Arguments to pass to az (optional)
Example:
az account showProcess JSON using jq.
Usage: jq [args]
Arguments:
[args] Arguments to pass to jq (optional)
Example:
query "SELECT * FROM c" | jq '.Documents[0]'Process JSON for tabular display.
Usage: jtab args
Arguments:
args Arguments to pass to jtab
The | operator pipes JSON results between commands.
Access values from piped JSON using paths starting with $:
$- The entire JSON result$.property- Access a property$.[0]- Access array element by index$.items[0].id- Chain access
# Enter first database from list
ls | cd $.[0]
# Get first item's ID
ls -m 1 | echo $.items[0].id
# Create items from array
echo '[{"id":"a"},{"id":"b"}]' | mkitem
# Extract nested property
echo '{"user":{"name":"Ada"}}' | echo $.user.name
# Query and process result
query "SELECT * FROM c" | echo $.Documents[0].idWhen starting Cosmos Shell from the command line:
| Argument | Description |
|---|---|
--cs <value> |
Color system (0=off, 1=standard, 2=true color) |
-c <command> |
Execute command and exit |
-k <command> |
Execute command and keep running |
--clearhistory |
Clear command history and exit |
--connect <string> |
Connection string to connect on startup |
--mcp |
Enable MCP server |
--mcp-port <port> |
MCP server port (0 for stdio) |
--help |
Display help |
--version |
Display version |
Examples:
# Start with connection
CosmosShell --connect "https://myaccount.documents.azure.com:443/"
# Execute command and exit
CosmosShell -c "connect 'endpoint'; ls"
# Start with MCP enabled
CosmosShell --mcp --mcp-port 6128- Scripting Guide - Write scripts and custom commands
- MCP Server Guide - Set up AI assistant integration