> This page location: /docs.md > /docs/tools-and-connectors.md > /docs/mongodb-vscode.md

> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

<!--
Tab options on this page. Append to the .md URL to filter:
  ?tabs=<id,...>   select specific tabs (e.g. ?tabs=nodejs,shell)
  ?allTabs=true    include every tab
  (no param)       default: one tab per tabset

Available tabs:
  other tabs: mdbview, mdboverview, cmdpalette, command-palette, mdb-view, standalone, replicaset, srvrecord, username-pw, oidc, x509, ldap, aws-iam, ssl, ssh
-->

# Connect to Your MongoDB Deployment

This page outlines how to use MongoDB for VS Code Extension to connect to a MongoDB host. You can connect to a standalone, replica set, or sharded cluster host.

**Note: MongoDB Atlas**

If you need to create a MongoDB host, consider using [MongoDB Atlas](https://www.mongodb.com/cloud/atlas). Atlas is a cloud-hosted database-as-a-service which requires no installation, offers a free option to get started, and provides a copyable URI to easily connect VS Code Extension to your deployment.

To create a free cluster on Atlas, run the command `MongoDB: Open Overview Page` in the Visual Studio Code Command Palette and then click Create free cluster.

To create an Atlas cluster using a Terraform template included with VS Code Extension, see [Create an Atlas Cluster from a Template using Terraform.](https://www.mongodb.com/docs/mongodb-vscode/create-cluster-terraform.md#std-label-vsce-create-cluster-terraform)

If you need to install VS Code Extension, see [Install MongoDB for VS Code Extension](https://www.mongodb.com/docs/mongodb-vscode/install.md#std-label-vsce-install) for instructions.

## Considerations

- When connecting VS Code Extension to a replica set, use either the replica set SRV record or Replica Set Name when filling in your connection information. It is not recommended to connect directly to an individual replica set member.

  - If the member to which you are connected switches from a [primary](https://www.mongodb.com/docs/manual/core/replica-set-primary/) member to a [secondary](https://www.mongodb.com/docs/manual/core/replica-set-secondary/) or vice versa as the result of an election, VS Code Extension may either forcibly close the connection or display stale data.

- You can't connect VS Code Extension directly to an [analytics node.](https://www.mongodb.com/docs/atlas/faq/#what-are-analytics-nodes)

- VS Code Extension appends the `appName` connection string option with a value of `mongodb-vscode <version>` for all deployment connections.

- VS Code Extension automatically starts the MongoDB MCP Server when you connect to your MongoDB deployment. You can disable this behavior upon first connection, or at any time by using the [mdb.mcp.server](https://www.mongodb.com/docs/mongodb-vscode/settings.md#std-label-vsce-setting-mcp-server) setting.

  To learn more, see [MongoDB MCP Server in MongoDB VS Code Extension.](https://www.mongodb.com/docs/mongodb-vscode/mcp-server.md#std-label-vsce-mcp-server)

## Create a Connection

Select the method you want to use to connect to your deployment using the selector option at the top of the page. VS Code Extension provides three options to connect to your deployment:

| Connection Method | Description |
| --- | --- |
| Connect with Connection String | This method is faster and easier than using the advanced connection settings. Use this option if your deployment is hosted on Atlas or you already have a connection string for a deployment available. |
| Advanced Connection Settings | This method lets you build a connection string with a form. Use this option if you need to customize the connection string and want to see available connection options. |
| Atlas CLI | This method lets you connect using existing Atlas CLI configurations. Use this option if you want to connect to an Atlas deployment and have installed the Atlas CLI. |

**Note:**

To specify where VS Code Extension connections are saved, use the Default Connection Saving Location [setting.](https://www.mongodb.com/docs/mongodb-vscode/settings.md#std-label-vsce-settings)

VS Code Extension uses the VS Code API to store and encrypt connection strings and credentials. To learn more about how VS Code encrypts connections, see the [VS Code API documentation.](https://code.visualstudio.com/api/references/vscode-api#SecretStorage)

When you provide a connection string, VS Code Extension supports most [Connection String Options](https://www.mongodb.com/docs/manual/reference/connection-string/#connection-string-options) supported by MongoDB.

1. Obtain your connection string.

   You can use either the [Standard Connection String Format](https://www.mongodb.com/docs/manual/reference/connection-string/#connections-standard-connection-string-format) or the [DNS Seedlist Connection Format.](https://www.mongodb.com/docs/manual/reference/connection-string/#connections-dns-seedlist)

   - To obtain the connection string for an Atlas cluster:

     Navigate to your Atlas Clusters view.

     Click Connect for your desired cluster.

     Click Connect with MongoDB Compass.

     Copy the provided connection string.

   - To learn how to format the connection string for a deployment which is not hosted on Atlas, see [Connection String URI Format.](https://www.mongodb.com/docs/manual/reference/connection-string/)

2. Open the Visual Studio Code Command Palette.

   Open the Visual Studio Code Command Palette to paste your connection string and connect to your cluster. You can open the Command Palette in one of the following ways:

   ### Open from the Activity Bar

   Select the MongoDB icon from the left side menu bar in VSCode.

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

   Expand the Connections pane in the left navigation if it is collapsed.

   ![Image showing connections pane](/images/vsce-expand-connections.png)

   Click the More Actions menu (...) and select Add MongoDB Connection with Connection
   String....

   ![Select add connection with connection string](/images/vsce-mongodb-connection-dots.png)

3. Paste your connection string into the Command Palette.

   **Important:**

   If your deployment requires authentication, ensure that you update the connection string with credentials of a database user for your deployment. The connection might succeed without these credentials, but you won't be able to interact with data in your deployment.

4. Press the **Enter** or **Return** key.

## Connect to Atlas Stream Processing

**New in version 1.50**

You can use VS Code Extension to connect to [Atlas Stream Processing](https://www.mongodb.com/docs/atlas/atlas-stream-processing.md#std-label-atlas-sp-overview) by providing a Stream Processing Workspace (SPW) connection string.

For details on how to configure Atlas Stream Processing, see [Manage Stream Processing Workspaces.](https://www.mongodb.com/docs/atlas/atlas-stream-processing/manage-processing-instance.md#std-label-atlas-sp-manage-spi)

1. Open the connections pane

   Expand the Connections pane in the left navigation if it is collapsed.

   Click the More Actions menu (...) and select Add MongoDB Connection with Connection String...

2. Paste in an SPW connection string

   To obtain an SPW connection string login to your [Atlas](https://www.mongodb.com/docs/atlas/) account. Click Stream Processing from the left-hand navigation and then select a Stream Processing Workspace. Click Connect and choose MongoDB for VSCode from the Choose a Connection Method page of the connect dialog.

   **Tip:**

   For full details on using and configuring Atlas Stream Processing, see [Atlas Stream Processing.](https://www.mongodb.com/docs/atlas/atlas-stream-processing.md#std-label-atlas-sp-overview)

   The following code block is an example of SPW connection string:

   ```text
   mongodb://user1:password1@atlas-stream-xxxxxxxxxxxxxxxxxxxxxxxx-yyyyy.virginia-usa.a.query.mongodb.net/?authSource=admin&readPreference=primary&ssl=true&directConnection=true
   ```

   Once you are connected, the stream connection displays under the Connections pane:

   ![Image of a stream connection](/images/vsce-stream-connection-example.png)

3. Open a new VS Code Extension playground

   After successfully connecting to your Atlas Stream, click Create New Playground on the Playgrounds pane. A stream processing playground template displays with pre-populated code that allows you to list stream connections and process stream data:

   ![Image of a stream processing template](/images/vsce-stream-connection-playground.png)

4. Create a Stream Processor You can create new Stream Processors from the VS Code Extension Connections pane.

   Right click over your Stream Processing connection.

   From the menu, select Add streamProcessor. A Stream Processor JavaScript file will open for you to fill in.

   Once you have filled in your streamProcessor JavaScript Playground file, click over the Play button at the top level of your VS Code Extension space.

   ![Image of the add stream processor menu option](/images/vsce-add-stream-processor.png)

5. Start, Stop or Drop a Stream Processor

   You can manage your Stream Processors from the VS Code Extension Connections pane. Right-click over the Stream Processor of your connection and select the option that you want to apply to your Stream Processor.

   ![Image of the stream processors options in VSCode](/images/vsce-sp-options.png)

## Activate a Connection

You can connect VS Code Extension to only one deployment at a time. To change the active connection to a different deployment, or to connect to a deployment from which you were disconnected:

1. In Visual Studio Code, click the MongoDB icon in the Activity Bar.

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

2. Right-click the connection you want to activate, then click Connect

### Launch MongoDB Shell

You can connect the [MongoDB Shell](https://www.mongodb.com/docs/mongodb-shell/) or legacy [`mongo`](https://www.mongodb.com/docs/manual/reference/mongo.md#mongodb-binary-bin.mongo) shell to your active deployment.

#### Considerations

- The shell that VS Code Extension uses to connect to your deployment is determined by the Shell setting in your [extension settings](https://www.mongodb.com/docs/mongodb-vscode/settings.md#std-label-vsce-settings). You can choose either the [MongoDB Shell](https://www.mongodb.com/docs/mongodb-shell/) or the legacy [`mongo`](https://www.mongodb.com/docs/manual/reference/mongo.md#mongodb-binary-bin.mongo) shell.

- The path to your selected shell must exist in your system's `PATH`. If it does not exist in your `PATH`, the operation errors.

#### Procedure

To connect the shell to your active deployment:

In the VS Code Extension Connections list, right-click your active deployment.

Select Launch MongoDB Shell.

VS Code Extension opens the Terminal window in VS Code and launches the shell connected to your selected deployment.

**See also:**

[Perform CRUD Operations in the MongoDB Shell](https://www.mongodb.com/docs/mongodb-shell/crud/)

## Edit a Connection

1. In Visual Studio Code, click the MongoDB icon in the Activity Bar

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

2. Expand the Connections pane

   Expand the Connections pane in the left navigation if it's collapsed.

   ![Image showing connections pane](/images/vsce-expand-connections.png)

3. Select a connection

   From the Connections menu, right-click the connection and select Edit Connection...

4. Make changes and save

   Click  Advanced Connection Options to display the advanced connection form.

   **Tip:**

   You can also click the Edit Connection String toggle in the top-right of the form to edit the connection string URI directly.

   Once you are done editing the connection options click Save & Connect.

## Copy a Connection

You can copy a connection string from an existing Visual Studio Code connection.

1. In Visual Studio Code, click the MongoDB icon in the Activity Bar

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

2. Expand the Connections pane

   Expand the Connections pane in the left navigation if it's collapsed.

   ![Image showing connections pane](/images/vsce-expand-connections.png)

3. Select a connection

   From the Connections menu, right-click the connection and select Copy Connection String.

   The connection string is copied to your clipboard.

## Rename a Connection

To rename a connection to a deployment in VS Code Extension:

1. In Visual Studio Code, click the MongoDB icon in the Activity Bar.

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

2. Right-click the connection you want to activate, then click Rename Connection.

3. Rename the connection.

   In the Command Palette, type a new name for the connection.

   Press the **Enter** or **Return** key to rename the connection.

## Disconnect from a Deployment

VS Code Extension provides two methods to disconnect from a deployment. You can:

- Disconnect with the Command Palette.

- Disconnect from the MongoDB view in the Activity Bar.

### Command Palette

1. Open the Command Palette

   | Operating System | Method | Actions |
   | --- | --- | --- |
   | Any | Visual Studio Code Menu | View > Command Palette |
   | MacOS | Keyboard Shortcut | Press `Command` + `Shift` + `P` |
   | Windows and Linux | Keyboard Shortcut | Press `Control` + `Shift` + `P` |

2. Disconnect

   From the Command Palette, select MongoDB: Disconnect.

   **Tip:**

   Enter `mongodb` in the Command Palette to display all of the VS Code Extension commands you can use.

   Press **Enter**.

Disconnecting from a MongoDB instance closes the VS Code Extension connection to the active instance. You must [reconnect](https://www.mongodb.com/docs/mongodb-vscode/connect.md#std-label-vsce-connect-task) to interact with data in your deployment again.

## Remove a Connection

VS Code Extension provides two methods to remove a connection to a deployment from Visual Studio Code. You can:

- Remove a connection from the MongoDB view in the Activity Bar.

- Remove a connection with the Command Palette.

**Important:**

Removing a connection from Visual Studio Code removes it both from the current workspace and from Visual Studio Code globally.

### MongoDB View

1. In Visual Studio Code, click the MongoDB icon in the Activity Bar.

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

2. Right-click the connection you want to remove, then click Remove Connection.

3. Click Yes to remove the connection.

**See also:**

[Connect to a Deployment from a Playground](https://www.mongodb.com/docs/mongodb-vscode/playgrounds.md#std-label-playground-connect-to-deployment)

This page outlines how to use MongoDB for VS Code Extension to connect to a MongoDB host. You can connect to a standalone, replica set, or sharded cluster host.

**Note: MongoDB Atlas**

If you need to create a MongoDB host, consider using [MongoDB Atlas](https://www.mongodb.com/cloud/atlas). Atlas is a cloud-hosted database-as-a-service which requires no installation, offers a free option to get started, and provides a copyable URI to easily connect VS Code Extension to your deployment.

To create a free cluster on Atlas, run the command `MongoDB: Open Overview Page` in the Visual Studio Code Command Palette and then click Create free cluster.

To create an Atlas cluster using a Terraform template included with VS Code Extension, see [Create an Atlas Cluster from a Template using Terraform.](https://www.mongodb.com/docs/mongodb-vscode/create-cluster-terraform.md#std-label-vsce-create-cluster-terraform)

If you need to install VS Code Extension, see [Install MongoDB for VS Code Extension](https://www.mongodb.com/docs/mongodb-vscode/install.md#std-label-vsce-install) for instructions.

## Considerations

- When connecting VS Code Extension to a replica set, use either the replica set SRV record or Replica Set Name when filling in your connection information. It is not recommended to connect directly to an individual replica set member.

  - If the member to which you are connected switches from a [primary](https://www.mongodb.com/docs/manual/core/replica-set-primary/) member to a [secondary](https://www.mongodb.com/docs/manual/core/replica-set-secondary/) or vice versa as the result of an election, VS Code Extension may either forcibly close the connection or display stale data.

- You can't connect VS Code Extension directly to an [analytics node.](https://www.mongodb.com/docs/atlas/faq/#what-are-analytics-nodes)

- VS Code Extension appends the `appName` connection string option with a value of `mongodb-vscode <version>` for all deployment connections.

- VS Code Extension automatically starts the MongoDB MCP Server when you connect to your MongoDB deployment. You can disable this behavior upon first connection, or at any time by using the [mdb.mcp.server](https://www.mongodb.com/docs/mongodb-vscode/settings.md#std-label-vsce-setting-mcp-server) setting.

  To learn more, see [MongoDB MCP Server in MongoDB VS Code Extension.](https://www.mongodb.com/docs/mongodb-vscode/mcp-server.md#std-label-vsce-mcp-server)

## Create a Connection

Select the method you want to use to connect to your deployment using the selector option at the top of the page. VS Code Extension provides three options to connect to your deployment:

| Connection Method | Description |
| --- | --- |
| Connect with Connection String | This method is faster and easier than using the advanced connection settings. Use this option if your deployment is hosted on Atlas or you already have a connection string for a deployment available. |
| Advanced Connection Settings | This method lets you build a connection string with a form. Use this option if you need to customize the connection string and want to see available connection options. |
| Atlas CLI | This method lets you connect using existing Atlas CLI configurations. Use this option if you want to connect to an Atlas deployment and have installed the Atlas CLI. |

**Note:**

To specify where VS Code Extension connections are saved, use the Default Connection Saving Location [setting.](https://www.mongodb.com/docs/mongodb-vscode/settings.md#std-label-vsce-settings)

VS Code Extension uses the VS Code API to store and encrypt connection strings and credentials. To learn more about how VS Code encrypts connections, see the [VS Code API documentation.](https://code.visualstudio.com/api/references/vscode-api#SecretStorage)

1. In Visual Studio Code, click the MongoDB icon in the Activity Bar.

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

2. Open the VS Code Extension Overview page.

   You can use the the MongoDB view or the Command Palette to open the overview page:

   ### MongoDB View

   Expand the Connections pane in the left navigation if it's collapsed.

   ![Image showing connections pane](/images/vsce-expand-connections.png)

   Click the More Actions menu (...), then click Add MongoDB Connection to open the VS Code Extension *Overview* page.

   ![Image showing connections pane dots](/images/vsce-mongodb-connection-dots.png)

3. Open the Advanced Connection Settings Form.

   On the *Overview* page, click Open form under Advanced Connection Settings.

   ![Image showing connections pane screen](/images/vsce-mongodb-connection-screen.png)

4. Enter your connection information.

   **Important:**

   VS Code Extension does not support the following connection options:

   - CSFLE In-Use Encryption

   - Kerberos Authentication

   The General tab contains the options [Connection Type](https://www.mongodb.com/docs/mongodb-vscode/connect.md#std-label-vscode-connect-connection-type-option) and [Authentication](https://www.mongodb.com/docs/mongodb-vscode/connect.md#std-label-vscode-connect-authentication-option). Use the following instructions to configure your connections options:

   ##### Connection Type

   To configure the **Connection Type** option, select the type of connection for your MongoDB deployment:

   ### Standalone

   For a [Standalone](https://www.mongodb.com/docs/manual/reference/connection-string/#dns-seedlist-connection-format), specify the following:

   - Hostname of the machine where the deployment is running.

     If you are running your deployment locally, this value is `localhost`. If you are connecting to an Atlas cluster, you can get your hostname from your cluster detail view in Atlas.

     If you are not sure of your hostname, contact your Database Administrator for information.

   - Port on which the deployment is running.

     By default, a standalone deployment operates on port `27017`. For more information on the default ports MongoDB operates on, see [Default MongoDB Port.](https://www.mongodb.com/docs/manual/reference/default-mongodb-port/)

     If you are not sure of the port where your deployment operates, contact your Database Administrator for information.

   Click  to specify additional hostnames and associated ports.

   ##### Authentication

   Configure authentication using the **Authentication** option if your deployment requires it. Atlas clusters use Username / Password authentication.

   Select your authentication method for specific instructions:

   ### Username / Password

   Select Username / Password if the deployment uses MongoDB-CR, [SCRAM-SHA-1](https://www.mongodb.com/docs/manual/core/security-scram/), or [SCRAM-SHA-256](https://www.mongodb.com/docs/manual/core/security-scram/) as its authentication mechanism.

   Provide the Username, Password, and [Authentication Database](https://www.mongodb.com/docs/manual/core/security-users/#user-authentication-database) to authenticate the user.

   If you are connecting to your deployment using TLS/SSL or an SSH tunnel, refer to the following tabs for specific instructions:

   ### Connect Using TLS/SSL

   This option directs VS Code Extension to connect to your MongoDB deployment via TLS/SSL. You can select one of the following SSL options:

   | Option | Description |
   | --- | --- |
   | System CA/Atlas Deployment | Connect to [MongoDB Atlas](https://www.mongodb.com/cloud/atlas). |
   | Server Validation | VS Code Extension validates the identity of the deployment. If selected, you must provide: Certificate AuthorityOne or more certificate files from trusted Certificate Authorities to validate the certificate provided by the deployment. |
   | Server and Client Validation | The deployment performs certificate validation from its clients and VS Code Extension validates the identity of the deployment. If selected, you must provide: Certificate Authority FileOne or more certificate files from trusted Certificate Authorities to validate the certificate provided by the deployment.Client CertificateA TLS/SSL certificate to present to the deployment to verify the identity of the connecting client. Typical file extensions for the certificate are `.crt` or `.pem`.Client Private KeyA TLS/SSL key file to the deployment to verify the identity of the connecting client. Typical file extensions for the private key are `.key` or `.pem`.Client Key PasswordIf the *Client Private Key* is protected with a password/passphrase, you must provide the password/passphrase. |
   | Unvalidated (Insecure) | Use TLS/SSL without any identity validation. |

   **Tip:**

   For production use, your MongoDB deployment should use valid certificates generated and signed by a single certificate authority. You or your organization can generate and maintain an independent certificate authority, or use certificates generated by a third-party TLS/SSL vendor.

5. Optional: Specify additional options in the Advanced tab.

   You can select the Read Preference, which specifies how VS Code Extension directs read operations:

   | Read Preference Mode | Description |
   | --- | --- |
   | Primary | Default mode. All operations read from the current replica set primary. |
   | Primary Preferred | In most situations, operations read from the primary but if it is unavailable, operations read from secondary members. |
   | Secondary | All operations read from the secondary members of the replica set. |
   | Secondary Preferred | In most situations, operations read from secondary members but if no secondary members are available, operations read from the primary. |
   | Nearest | Operations read from member of the replica set with the least network latency, irrespective of the member's type. |

   If omitted, defaults to Primary. To learn more about read preferences, see [Read Preference.](https://www.mongodb.com/docs/manual/core/read-preference/)

   You can specify additional MongoDB connection behavior with the following options:

   | Field | Description |
   | --- | --- |
   | Replica Set Name | (Optional) Name of replica set. |
   | Default Authentication Database | (Optional) Authentication database used when authSource is not specified. For more information, see [Authentication Options.](https://www.mongodb.com/docs/manual/reference/connection-string/#authentication-options) |
   | URI Options | Additional options to customize your connection. You specify these options as key-value pairs, and Visual Studio Code automatically adds the key-value pairs to the connection string. For more information, see [Connection String Options.](https://www.mongodb.com/docs/manual/reference/connection-string/#connection-string-options) |

6. Click Connect.

## Connect to Atlas Stream Processing

**New in version 1.50**

You can use VS Code Extension to connect to [Atlas Stream Processing](https://www.mongodb.com/docs/atlas/atlas-stream-processing.md#std-label-atlas-sp-overview) by providing a Stream Processing Workspace (SPW) connection string.

For details on how to configure Atlas Stream Processing, see [Manage Stream Processing Workspaces.](https://www.mongodb.com/docs/atlas/atlas-stream-processing/manage-processing-instance.md#std-label-atlas-sp-manage-spi)

1. Open the connections pane

   Expand the Connections pane in the left navigation if it is collapsed.

   Click the More Actions menu (...) and select Add MongoDB Connection with Connection String...

2. Paste in an SPW connection string

   To obtain an SPW connection string login to your [Atlas](https://www.mongodb.com/docs/atlas/) account. Click Stream Processing from the left-hand navigation and then select a Stream Processing Workspace. Click Connect and choose MongoDB for VSCode from the Choose a Connection Method page of the connect dialog.

   **Tip:**

   For full details on using and configuring Atlas Stream Processing, see [Atlas Stream Processing.](https://www.mongodb.com/docs/atlas/atlas-stream-processing.md#std-label-atlas-sp-overview)

   The following code block is an example of SPW connection string:

   ```text
   mongodb://user1:password1@atlas-stream-xxxxxxxxxxxxxxxxxxxxxxxx-yyyyy.virginia-usa.a.query.mongodb.net/?authSource=admin&readPreference=primary&ssl=true&directConnection=true
   ```

   Once you are connected, the stream connection displays under the Connections pane:

   ![Image of a stream connection](/images/vsce-stream-connection-example.png)

3. Open a new VS Code Extension playground

   After successfully connecting to your Atlas Stream, click Create New Playground on the Playgrounds pane. A stream processing playground template displays with pre-populated code that allows you to list stream connections and process stream data:

   ![Image of a stream processing template](/images/vsce-stream-connection-playground.png)

4. Create a Stream Processor You can create new Stream Processors from the VS Code Extension Connections pane.

   Right click over your Stream Processing connection.

   From the menu, select Add streamProcessor. A Stream Processor JavaScript file will open for you to fill in.

   Once you have filled in your streamProcessor JavaScript Playground file, click over the Play button at the top level of your VS Code Extension space.

   ![Image of the add stream processor menu option](/images/vsce-add-stream-processor.png)

5. Start, Stop or Drop a Stream Processor

   You can manage your Stream Processors from the VS Code Extension Connections pane. Right-click over the Stream Processor of your connection and select the option that you want to apply to your Stream Processor.

   ![Image of the stream processors options in VSCode](/images/vsce-sp-options.png)

## Activate a Connection

You can connect VS Code Extension to only one deployment at a time. To change the active connection to a different deployment, or to connect to a deployment from which you were disconnected:

1. In Visual Studio Code, click the MongoDB icon in the Activity Bar.

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

2. Right-click the connection you want to activate, then click Connect

### Launch MongoDB Shell

You can connect the [MongoDB Shell](https://www.mongodb.com/docs/mongodb-shell/) or legacy [`mongo`](https://www.mongodb.com/docs/manual/reference/mongo.md#mongodb-binary-bin.mongo) shell to your active deployment.

#### Considerations

- The shell that VS Code Extension uses to connect to your deployment is determined by the Shell setting in your [extension settings](https://www.mongodb.com/docs/mongodb-vscode/settings.md#std-label-vsce-settings). You can choose either the [MongoDB Shell](https://www.mongodb.com/docs/mongodb-shell/) or the legacy [`mongo`](https://www.mongodb.com/docs/manual/reference/mongo.md#mongodb-binary-bin.mongo) shell.

- The path to your selected shell must exist in your system's `PATH`. If it does not exist in your `PATH`, the operation errors.

#### Procedure

To connect the shell to your active deployment:

In the VS Code Extension Connections list, right-click your active deployment.

Select Launch MongoDB Shell.

VS Code Extension opens the Terminal window in VS Code and launches the shell connected to your selected deployment.

**See also:**

[Perform CRUD Operations in the MongoDB Shell](https://www.mongodb.com/docs/mongodb-shell/crud/)

## Edit a Connection

1. In Visual Studio Code, click the MongoDB icon in the Activity Bar

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

2. Expand the Connections pane

   Expand the Connections pane in the left navigation if it's collapsed.

   ![Image showing connections pane](/images/vsce-expand-connections.png)

3. Select a connection

   From the Connections menu, right-click the connection and select Edit Connection...

4. Make changes and save

   Click  Advanced Connection Options to display the advanced connection form.

   **Tip:**

   You can also click the Edit Connection String toggle in the top-right of the form to edit the connection string URI directly.

   Once you are done editing the connection options click Save & Connect.

## Copy a Connection

You can copy a connection string from an existing Visual Studio Code connection.

1. In Visual Studio Code, click the MongoDB icon in the Activity Bar

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

2. Expand the Connections pane

   Expand the Connections pane in the left navigation if it's collapsed.

   ![Image showing connections pane](/images/vsce-expand-connections.png)

3. Select a connection

   From the Connections menu, right-click the connection and select Copy Connection String.

   The connection string is copied to your clipboard.

## Rename a Connection

To rename a connection to a deployment in VS Code Extension:

1. In Visual Studio Code, click the MongoDB icon in the Activity Bar.

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

2. Right-click the connection you want to activate, then click Rename Connection.

3. Rename the connection.

   In the Command Palette, type a new name for the connection.

   Press the **Enter** or **Return** key to rename the connection.

## Disconnect from a Deployment

VS Code Extension provides two methods to disconnect from a deployment. You can:

- Disconnect with the Command Palette.

- Disconnect from the MongoDB view in the Activity Bar.

### Command Palette

1. Open the Command Palette

   | Operating System | Method | Actions |
   | --- | --- | --- |
   | Any | Visual Studio Code Menu | View > Command Palette |
   | MacOS | Keyboard Shortcut | Press `Command` + `Shift` + `P` |
   | Windows and Linux | Keyboard Shortcut | Press `Control` + `Shift` + `P` |

2. Disconnect

   From the Command Palette, select MongoDB: Disconnect.

   **Tip:**

   Enter `mongodb` in the Command Palette to display all of the VS Code Extension commands you can use.

   Press **Enter**.

Disconnecting from a MongoDB instance closes the VS Code Extension connection to the active instance. You must [reconnect](https://www.mongodb.com/docs/mongodb-vscode/connect.md#std-label-vsce-connect-task) to interact with data in your deployment again.

## Remove a Connection

VS Code Extension provides two methods to remove a connection to a deployment from Visual Studio Code. You can:

- Remove a connection from the MongoDB view in the Activity Bar.

- Remove a connection with the Command Palette.

**Important:**

Removing a connection from Visual Studio Code removes it both from the current workspace and from Visual Studio Code globally.

### MongoDB View

1. In Visual Studio Code, click the MongoDB icon in the Activity Bar.

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

2. Right-click the connection you want to remove, then click Remove Connection.

3. Click Yes to remove the connection.

**See also:**

[Connect to a Deployment from a Playground](https://www.mongodb.com/docs/mongodb-vscode/playgrounds.md#std-label-playground-connect-to-deployment)

This page outlines how to use MongoDB for VS Code Extension to connect to a MongoDB host. You can connect to a standalone, replica set, or sharded cluster host.

**Note: MongoDB Atlas**

If you need to create a MongoDB host, consider using [MongoDB Atlas](https://www.mongodb.com/cloud/atlas). Atlas is a cloud-hosted database-as-a-service which requires no installation, offers a free option to get started, and provides a copyable URI to easily connect VS Code Extension to your deployment.

To create a free cluster on Atlas, run the command `MongoDB: Open Overview Page` in the Visual Studio Code Command Palette and then click Create free cluster.

To create an Atlas cluster using a Terraform template included with VS Code Extension, see [Create an Atlas Cluster from a Template using Terraform.](https://www.mongodb.com/docs/mongodb-vscode/create-cluster-terraform.md#std-label-vsce-create-cluster-terraform)

If you need to install VS Code Extension, see [Install MongoDB for VS Code Extension](https://www.mongodb.com/docs/mongodb-vscode/install.md#std-label-vsce-install) for instructions.

## Considerations

- When connecting VS Code Extension to a replica set, use either the replica set SRV record or Replica Set Name when filling in your connection information. It is not recommended to connect directly to an individual replica set member.

  - If the member to which you are connected switches from a [primary](https://www.mongodb.com/docs/manual/core/replica-set-primary/) member to a [secondary](https://www.mongodb.com/docs/manual/core/replica-set-secondary/) or vice versa as the result of an election, VS Code Extension may either forcibly close the connection or display stale data.

- You can't connect VS Code Extension directly to an [analytics node.](https://www.mongodb.com/docs/atlas/faq/#what-are-analytics-nodes)

- VS Code Extension appends the `appName` connection string option with a value of `mongodb-vscode <version>` for all deployment connections.

- VS Code Extension automatically starts the MongoDB MCP Server when you connect to your MongoDB deployment. You can disable this behavior upon first connection, or at any time by using the [mdb.mcp.server](https://www.mongodb.com/docs/mongodb-vscode/settings.md#std-label-vsce-setting-mcp-server) setting.

  To learn more, see [MongoDB MCP Server in MongoDB VS Code Extension.](https://www.mongodb.com/docs/mongodb-vscode/mcp-server.md#std-label-vsce-mcp-server)

## Create a Connection

Select the method you want to use to connect to your deployment using the selector option at the top of the page. VS Code Extension provides three options to connect to your deployment:

| Connection Method | Description |
| --- | --- |
| Connect with Connection String | This method is faster and easier than using the advanced connection settings. Use this option if your deployment is hosted on Atlas or you already have a connection string for a deployment available. |
| Advanced Connection Settings | This method lets you build a connection string with a form. Use this option if you need to customize the connection string and want to see available connection options. |
| Atlas CLI | This method lets you connect using existing Atlas CLI configurations. Use this option if you want to connect to an Atlas deployment and have installed the Atlas CLI. |

**Note:**

To specify where VS Code Extension connections are saved, use the Default Connection Saving Location [setting.](https://www.mongodb.com/docs/mongodb-vscode/settings.md#std-label-vsce-settings)

VS Code Extension uses the VS Code API to store and encrypt connection strings and credentials. To learn more about how VS Code encrypts connections, see the [VS Code API documentation.](https://code.visualstudio.com/api/references/vscode-api#SecretStorage)

The [Atlas CLI](https://www.mongodb.com/docs/atlas/cli/current/) allows you to connect to both your local and Atlas deployments from MongoDB for VsCode. Before beginning, [install the Atlas CLI.](https://www.mongodb.com/docs/atlas/cli/current/install-atlas-cli/)

1. Connect from the Atlas CLI.

   In your terminal, run `atlas auth login` to authenticate with your Atlas login credentials. To learn more, see [Connect from the Atlas CLI.](https://www.mongodb.com/docs/atlas/cli/current/connect-atlas-cli/)

2. Run the connection command.

   Run `atlas deployment connect` in your terminal.

   ```text
   atlas deployment connect
   ```

3. Select your deployment.

   Select the deployment you wish to connect to from your list of deployments.

4. Select VS Code Extension as your connection method.

   The Atlas CLI prompts you to select your connection method. Select **"vscode - MongoDB for VsCode"**.

5. Open Visual Studio Code and click the MongoDB icon in the Activity Bar.

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

   You can view your connected deployment under Connections.

   ![Image showing connections pane](/images/vsce-expand-connections.png)

## Connect to Atlas Stream Processing

**New in version 1.50**

You can use VS Code Extension to connect to [Atlas Stream Processing](https://www.mongodb.com/docs/atlas/atlas-stream-processing.md#std-label-atlas-sp-overview) by providing a Stream Processing Workspace (SPW) connection string.

For details on how to configure Atlas Stream Processing, see [Manage Stream Processing Workspaces.](https://www.mongodb.com/docs/atlas/atlas-stream-processing/manage-processing-instance.md#std-label-atlas-sp-manage-spi)

1. Open the connections pane

   Expand the Connections pane in the left navigation if it is collapsed.

   Click the More Actions menu (...) and select Add MongoDB Connection with Connection String...

2. Paste in an SPW connection string

   To obtain an SPW connection string login to your [Atlas](https://www.mongodb.com/docs/atlas/) account. Click Stream Processing from the left-hand navigation and then select a Stream Processing Workspace. Click Connect and choose MongoDB for VSCode from the Choose a Connection Method page of the connect dialog.

   **Tip:**

   For full details on using and configuring Atlas Stream Processing, see [Atlas Stream Processing.](https://www.mongodb.com/docs/atlas/atlas-stream-processing.md#std-label-atlas-sp-overview)

   The following code block is an example of SPW connection string:

   ```text
   mongodb://user1:password1@atlas-stream-xxxxxxxxxxxxxxxxxxxxxxxx-yyyyy.virginia-usa.a.query.mongodb.net/?authSource=admin&readPreference=primary&ssl=true&directConnection=true
   ```

   Once you are connected, the stream connection displays under the Connections pane:

   ![Image of a stream connection](/images/vsce-stream-connection-example.png)

3. Open a new VS Code Extension playground

   After successfully connecting to your Atlas Stream, click Create New Playground on the Playgrounds pane. A stream processing playground template displays with pre-populated code that allows you to list stream connections and process stream data:

   ![Image of a stream processing template](/images/vsce-stream-connection-playground.png)

4. Create a Stream Processor You can create new Stream Processors from the VS Code Extension Connections pane.

   Right click over your Stream Processing connection.

   From the menu, select Add streamProcessor. A Stream Processor JavaScript file will open for you to fill in.

   Once you have filled in your streamProcessor JavaScript Playground file, click over the Play button at the top level of your VS Code Extension space.

   ![Image of the add stream processor menu option](/images/vsce-add-stream-processor.png)

5. Start, Stop or Drop a Stream Processor

   You can manage your Stream Processors from the VS Code Extension Connections pane. Right-click over the Stream Processor of your connection and select the option that you want to apply to your Stream Processor.

   ![Image of the stream processors options in VSCode](/images/vsce-sp-options.png)

## Activate a Connection

You can connect VS Code Extension to only one deployment at a time. To change the active connection to a different deployment, or to connect to a deployment from which you were disconnected:

1. In Visual Studio Code, click the MongoDB icon in the Activity Bar.

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

2. Right-click the connection you want to activate, then click Connect

### Launch MongoDB Shell

You can connect the [MongoDB Shell](https://www.mongodb.com/docs/mongodb-shell/) or legacy [`mongo`](https://www.mongodb.com/docs/manual/reference/mongo.md#mongodb-binary-bin.mongo) shell to your active deployment.

#### Considerations

- The shell that VS Code Extension uses to connect to your deployment is determined by the Shell setting in your [extension settings](https://www.mongodb.com/docs/mongodb-vscode/settings.md#std-label-vsce-settings). You can choose either the [MongoDB Shell](https://www.mongodb.com/docs/mongodb-shell/) or the legacy [`mongo`](https://www.mongodb.com/docs/manual/reference/mongo.md#mongodb-binary-bin.mongo) shell.

- The path to your selected shell must exist in your system's `PATH`. If it does not exist in your `PATH`, the operation errors.

#### Procedure

To connect the shell to your active deployment:

In the VS Code Extension Connections list, right-click your active deployment.

Select Launch MongoDB Shell.

VS Code Extension opens the Terminal window in VS Code and launches the shell connected to your selected deployment.

**See also:**

[Perform CRUD Operations in the MongoDB Shell](https://www.mongodb.com/docs/mongodb-shell/crud/)

## Edit a Connection

1. In Visual Studio Code, click the MongoDB icon in the Activity Bar

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

2. Expand the Connections pane

   Expand the Connections pane in the left navigation if it's collapsed.

   ![Image showing connections pane](/images/vsce-expand-connections.png)

3. Select a connection

   From the Connections menu, right-click the connection and select Edit Connection...

4. Make changes and save

   Click  Advanced Connection Options to display the advanced connection form.

   **Tip:**

   You can also click the Edit Connection String toggle in the top-right of the form to edit the connection string URI directly.

   Once you are done editing the connection options click Save & Connect.

## Copy a Connection

You can copy a connection string from an existing Visual Studio Code connection.

1. In Visual Studio Code, click the MongoDB icon in the Activity Bar

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

2. Expand the Connections pane

   Expand the Connections pane in the left navigation if it's collapsed.

   ![Image showing connections pane](/images/vsce-expand-connections.png)

3. Select a connection

   From the Connections menu, right-click the connection and select Copy Connection String.

   The connection string is copied to your clipboard.

## Rename a Connection

To rename a connection to a deployment in VS Code Extension:

1. In Visual Studio Code, click the MongoDB icon in the Activity Bar.

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

2. Right-click the connection you want to activate, then click Rename Connection.

3. Rename the connection.

   In the Command Palette, type a new name for the connection.

   Press the **Enter** or **Return** key to rename the connection.

## Disconnect from a Deployment

VS Code Extension provides two methods to disconnect from a deployment. You can:

- Disconnect with the Command Palette.

- Disconnect from the MongoDB view in the Activity Bar.

### Command Palette

1. Open the Command Palette

   | Operating System | Method | Actions |
   | --- | --- | --- |
   | Any | Visual Studio Code Menu | View > Command Palette |
   | MacOS | Keyboard Shortcut | Press `Command` + `Shift` + `P` |
   | Windows and Linux | Keyboard Shortcut | Press `Control` + `Shift` + `P` |

2. Disconnect

   From the Command Palette, select MongoDB: Disconnect.

   **Tip:**

   Enter `mongodb` in the Command Palette to display all of the VS Code Extension commands you can use.

   Press **Enter**.

Disconnecting from a MongoDB instance closes the VS Code Extension connection to the active instance. You must [reconnect](https://www.mongodb.com/docs/mongodb-vscode/connect.md#std-label-vsce-connect-task) to interact with data in your deployment again.

## Remove a Connection

VS Code Extension provides two methods to remove a connection to a deployment from Visual Studio Code. You can:

- Remove a connection from the MongoDB view in the Activity Bar.

- Remove a connection with the Command Palette.

**Important:**

Removing a connection from Visual Studio Code removes it both from the current workspace and from Visual Studio Code globally.

### MongoDB View

1. In Visual Studio Code, click the MongoDB icon in the Activity Bar.

   ![Image VSCode side bar menu.](/images/vsce-mongodb-extension-sidemenu.png)

2. Right-click the connection you want to remove, then click Remove Connection.

3. Click Yes to remove the connection.

**See also:**

[Connect to a Deployment from a Playground](https://www.mongodb.com/docs/mongodb-vscode/playgrounds.md#std-label-playground-connect-to-deployment)
