DocumentDB for VS Code

User ManualBack to User Manual


How to Construct a URL That Opens the Extension

DocumentDB for VS Code supports activation through custom URLs, enabling you to integrate the extension seamlessly with your development environment and build deep links directly to your DocumentDB and MongoDB clusters. This powerful feature allows you to create shortcuts that can open specific connections, navigate to particular databases, or even jump directly to a collection view within the extension.

This URL-based activation is particularly useful for:

URL Syntax

The prefix for URLs handled by this extension is:

vscode://ms-azuretools.vscode-documentdb

A link names what it wants in the path, and supplies arguments for it in the query:

vscode://ms-azuretools.vscode-documentdb/<action>?<parameters>

Supported Actions

Action What it does Parameters
connect Opens a connection to a cluster, optionally navigating into it connectionString, database, collection
local Opens the DocumentDB Local setup wizard none
local/documentdb Opens the DocumentDB Local setup wizard none

Only the actions in this table are recognized. A link naming anything else is refused with an explanatory message — the extension never treats the path as a command name, so a link cannot reach extension functionality that is not listed here.

Links written before actions existed keep working. A URL with no action, such as vscode://ms-azuretools.vscode-documentdb?connectionString=..., means connect. You do not need to update existing links.

local accepts an optional local resource type. Currently, documentdb is the only supported type, and omitting it defaults to documentdb, so /local and /local/documentdb are equivalent. Unsupported resource types and additional path segments are refused rather than silently opening a different setup experience.

Supported Parameters

These apply to the connect action.

The following table lists all supported URL parameters:

Parameter Required Description Example Value
connectionString Yes The MongoDB/DocumentDB connection string (double URL-encoded) mongodb%253A%252F%252F...
database No Name of the database to open after connection myDatabase
collection No Collection to open (requires a database parameter or path) myCollection

Parameter Details

Double Encoding

The connectionString parameter must be encoded twice to ensure proper parsing. This is because the connection string itself contains special characters that need to be preserved through the URL parsing process.

Encoding Process

The encoding happens in two steps:

  1. First encoding: Standard URL encoding of the connection string
  2. Second encoding: URL encoding of the already-encoded string

For example, the string "mongo+srv://" would be transformed as follows:

  1. Original string:
    mongo+srv://
    
  2. First encoding:
    mongo%2Bsrv%3A%2F%2F
    
  3. Second encoding (final result):
    mongo%252Bsrv%253A%252F%252F
    

This double encoding ensures that the URL is correctly parsed by both the operating system and the extension.

Examples

Here are practical examples of URLs with their decoded connection strings for clarity:

Example 1: Basic Connection

vscode://ms-azuretools.vscode-documentdb?connectionString=mongodb%253A%252F%252Fusername%253Apassword%2540localhost%253A27017
Parameter Decoded Value
connectionString mongodb://username:password@localhost:27017

Example 2: Connection with Database Navigation

vscode://ms-azuretools.vscode-documentdb?connectionString=mongodb%253A%252F%252Fmyuser%253Amypass%2540localhost%253A27017&database=analytics
Parameter Decoded Value
connectionString mongodb://myuser:mypass@localhost:27017
database analytics

This URL will connect to the database and automatically navigate to the analytics database.

Example 3: Direct Collection Access

vscode://ms-azuretools.vscode-documentdb?connectionString=mongodb%253A%252F%252Fadmin%253Asecret%2540localhost%253A27017%252Fecommerce&database=ecommerce&collection=orders
Parameter Decoded Value
connectionString mongodb://admin:secret@localhost:27017/ecommerce
database ecommerce
collection orders

This URL will connect to the database, navigate to the ecommerce database, and open the Collection View for the orders collection.

Example 4: Open the DocumentDB Local Setup Wizard

Use this to take someone from a web page to a running local DocumentDB without asking them to find anything in the UI. It carries no parameters, because there is no connection yet — that is what the wizard is for.

vscode://ms-azuretools.vscode-documentdb/local

The explicit resource-type form is equivalent:

vscode://ms-azuretools.vscode-documentdb/local/documentdb

When URL handling confirmations are enabled in the extension settings, either form shows one confirmation before opening the setup wizard.

How It Works

When you click a DocumentDB for VS Code URL, the following process occurs:

  1. Activation: The vscode:// prefix tells the operating system to activate VS Code. The ms-azuretools.vscode-documentdb segment activates the DocumentDB for VS Code extension.

  2. Action routing: The extension reads the action from the path. An unrecognized action is refused rather than guessed at, so a mistyped link never acts on parameters you did not intend for it.

  3. Connection Handling (for connect):
    • The extension parses the connectionString parameter and creates a new connection in the Connections View.
    • If a connection with the same host and username already exists, the existing connection will be selected instead of creating a duplicate.
  4. Navigation (if additional parameters are provided):
    • If the database parameter is provided, the extension navigates to that database.
    • If both database and collection parameters are provided, the extension opens the Collection View for the specified collection.

Additional Notes