Docs HomeMongoDB for VS Code

Connect to Your MongoDB Deployment连接到您的MongoDB部署

This page outlines how to use MongoDB for VS Code to connect to a MongoDB host. 本页概述了如何使用MongoDB for VS Code连接到MongoDB主机。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. 如果您需要创建一个MongoDB主机,可以考虑使用MongoDB AtlasAtlas is a cloud-hosted database-as-a-service which requires no installation, offers a free tier to get started, and provides a copyable URI to easily connect MongoDB for VS Code to your deployment.Atlas是一个云托管的数据库即服务,无需安装,提供免费的入门层,并提供可复制的URI,可以轻松地将MongoDB for VS Code连接到您的部署。

To create a cluster on the Atlas free tier, run the command MongoDB: Open Overview Page in the Visual Studio Code Command Palette and then click Create free cluster.要在Atlas免费层上创建集群,请在Visual Studio Code命令面板中运行命令MongoDB:Open Overview Page,然后单击创建免费集群。

To create an Atlas cluster using a Terraform template included with MongoDB for VS Code, see Create an Atlas Cluster from a Template using Terraform.要使用MongoDB for VS Code中包含的Terraform模板创建Atlas集群,请参阅使用Terraform从模板创建阿特拉斯集群

If you need to install MongoDB for VS Code, see Install MongoDB for VS Code for instructions.如果您需要安装MongoDB for VS Code,请参阅install MongoDB for VSCode以获取说明。

Considerations注意事项

  • When connecting MongoDB for VS Code to a replica set, use either the replica set SRV record or Replica Set Name when filling in your connection information. 将MongoDB for VS Code连接到副本集时,请在填写连接信息时使用副本集SRV记录或副本集名称。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 member to a secondary or vice versa as the result of an election, MongoDB for VS Code may either forcibly close the connection or display stale data.如果您连接的成员由于选择而从primary成员切换到secondary成员,反之亦然,MongoDB for VS Code可能会强制关闭连接或显示过时的数据。
  • You can't connect MongoDB for VS Code directly to an analytics node.您不能将MongoDB for VS Code直接连接到分析节点
  • MongoDB for VS Code appends the appName connection string option with a value of mongodb-vscode <version> for all deployment connections.MongoDB for VS Code为所有部署连接添加值为MongoDB vscode<version>appName连接字符串选项。

Create a Connection to a Deployment创建到展开的连接

MongoDB for VS Code provides two methods to create a connection to a deployment. You can:MongoDB for VS Code提供了两种方法来创建到部署的连接。您可以:

  • Provide a deployment connection string, or提供部署连接字符串,或
  • Fill in a deployment information in specific fields.在特定字段中填写部署信息。

Providing a connection string is faster and easier than filling in a deployment's details. 提供连接字符串比填写部署的详细信息更快、更容易。Use this option if Atlas hosts your deployment or if you have a connection string for a deployment available.如果Atlas托管您的部署,或者您有可用的部署连接字符串,请使用此选项。

Define how your connection is saved with the Default Connection Saving Location setting:定义如何使用“默认连接保存位置”设置保存连接:

Setting背景Description描述
GlobalSave your connection globally in VS Code, so it can be accessed from any workspace.将您的连接全局保存在VS Code中,这样就可以从任何工作区访问它。
WorkspaceSave your connection in your workspace. You cannot access the connection from a different workspace.将连接保存在工作区中。无法从其他工作区访问连接。
SessionSave the connection for only this VS Code session. 只保存此VS Code会话的连接。The connection is lost when you close VS Code.关闭VS Code时,连接将丢失。

When you provide a connection string, MongoDB for VS Code supports most Connection String Options supported by MongoDB.当您提供连接字符串时,MongoDB for VS Code支持MongoDB支持的大多数连接字符串选项

1

Obtain your connection string.获取您的连接字符串。

You can use either the Standard Connection String Format or the DNS Seedlist Connection Format.您可以使用标准连接字符串格式DNS种子列表连接格式

  • To obtain the connection string for an Atlas cluster:要获取Atlas集群的连接字符串,请执行以下操作:

    1. Navigate to your Atlas Clusters view.导航到Atlas Clusters视图。
    2. Click Connect for your desired cluster.单击所需集群的“连接”。
    3. Click Connect with MongoDB Compass.单击“使用MongoDB Compass连接”。
    4. 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.要了解如何格式化未托管在Atlas上的部署的连接字符串,请参阅连接字符串URI格式
2

Open the Visual Studio Code Command Palette.打开Visual Studio Code命令面板。

Open the Visual Studio Code Command Palette to paste your connection string and connect to your cluster. 打开Visual Studio Code命令面板以粘贴连接字符串并连接到集群。You can open the Command Palette in one of the following ways:可以通过以下方式之一打开命令面板:

  1. Perform the action described in the following table for your operating system and method:针对您的操作系统和方法执行下表中描述的操作:

    Operating System操作系统Method方法Actions操作
    AnyVisual Studio Code MenuView > Command Palette
    MacOSKeyboard ShortcutPress Command + Shift + P
    Windows and LinuxKeyboard ShortcutPress Control + Shift + P
  2. From the Command Palette, select MongoDB: Open Overview Page.从命令调色板中,选择“MongoDB:打开概览页面”。

    Tip

    Enter mongodb in the Command Palette to display all of the MongoDB for VS Code commands you can use.在命令调色板中输入mongodb,以显示所有可以使用的mongodb for VS Code命令。

  3. In the Overview page, click Connect under the Connect with Connection String.在“概述”页面中,单击“使用连接字符串连接”下的“连接”。
  1. Expand the Connections pane in the left navigation if it is collapsed.如果左侧导航中的“连接”窗格已折叠,请展开该窗格。
  2. Click the More Actions menu (...) and select Add MongoDB Connection with Connection String....单击“更多操作”菜单(),然后选择“添加带有连接字符串的MongoDB连接…”。
  1. Perform the action described in the following table for your operating system and method:针对您的操作系统和方法执行下表中描述的操作:

    Operating System操作系统Method方法Actions操作
    AnyVisual Studio Code MenuView > Command Palette
    MacOSKeyboard ShortcutPress Command + Shift + P
    Windows and LinuxKeyboard ShortcutPress Control + Shift + P
  2. From the Command Palette, select MongoDB: Connect with Connection String....从命令调色板中,选择“MongoDB:使用连接字符串连接”。

    Tip

    Enter mongodb in the Command Palette to display all of the MongoDB for VS Code commands you can use.在命令调色板中输入mongodb,以显示所有可以使用的mongodb for VS Code命令。

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.EnterReturn键。

1

In Visual Studio Code, click the MongoDB view in the Activity Bar.在Visual Studio Code中,单击“活动栏”中的“MongoDB”视图。

2

Open the MongoDB for VS Code Overview page from the Command Palette or from the MongoDB view in the Activity Bar.从命令面板或活动栏中的“MongoDB”视图打开MongoDB for VS Code “概览”页面。

  1. Perform the action described in the following table for your operating system and method:针对您的操作系统和方法执行下表中描述的操作:

    Operating System操作系统Method方法Actions操作
    AnyVisual Studio Code MenuView > Command Palette
    MacOSKeyboard ShortcutPress Command + Shift + P
    Windows and LinuxKeyboard ShortcutPress Control + Shift + P
  2. From the Command Palette, select MongoDB: Open Overview Page.从命令调色板中,选择“MongoDB:打开概览页面”。

    Tip

    Enter mongodb in the Command Palette to display all of the MongoDB for VS Code commands you can use.在命令调色板中输入mongodb,以显示所有可以使用的mongodb for VS Code命令。

  1. Expand the Connections pane in the left navigation if it's collapsed.如果左侧导航中的“连接”窗格已折叠,请展开该窗格。
  2. Click the More Actions menu (...), then click Add MongoDB Connection to open the MongoDB for VS Code Overview page.单击更多操作菜单(),然后单击“添加MongoDB连接”以打开MongoDB for VS Code“概览”页面。
3

In the Overview page, click Open form under Advanced Connection Settings to create a connection to a deployment.在“概述”页面中,单击“高级连接设置”下的“打开表单”以创建到展开的连接。

4

Enter your connection information.输入您的连接信息。

Note

If you want to connect to your deployment using a connection string, click Connect with a connection string, then paste your connection string into the Command Palette.如果要使用连接字符串连接到部署,请单击“使用连接字符串进行连接”,然后将连接字符串粘贴到命令面板中。

For more information, see the Paste Connection String tab in Create a Connection to a Deployment.有关详细信息,请参阅创建到部署的连接中的“粘贴连接字符串”选项卡。

The General tab contains the following options:“常规”选项卡包含以下选项:

Option选项Description描述
Connection Type连接类型Type of connection. Select your connection type from the tabs below for specific instructions for defining that connection type:连接类型。从下面的选项卡中选择您的连接类型,以获取定义该连接类型的具体说明:

For a Standalone, specify the following:对于单机版,请指定以下内容:

  • Hostname of the machine where the deployment is running.正在运行部署的计算机的“主机名”。
    If you are running your deployment locally, this value is localhost. 如果您在本地运行部署,则此值为localhostIf you are connecting to an Atlas cluster, you can get your hostname from your cluster detail view in Atlas.如果您正在连接到Atlas集群,您可以从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. 默认情况下,独立部署在端口27017上运行。For more information on the default ports MongoDB operates on, see Default MongoDB Port.有关MongoDB操作的默认端口的更多信息,请参阅默认MongoDB端口
    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身份验证Authentication to use if the deployment requires authentication. 如果部署需要身份验证,则使用身份验证。Atlas clusters use Username / Password authentication.Atlas集群使用用户名/密码身份验证。
Select your authentication method from the tabs below for specific instructions:从下面的选项卡中选择您的身份验证方法以获取具体说明:

Select Username / Password if the deployment uses either MongoDB-CR or SCRAM-SHA-1 as its authentication mechanism.如果部署使用MongoDB CR或SCRAM-SHA-1作为身份验证机制,请选择用户名/密码
Provide the Username, Password, and Authentication Database to authenticate the user.提供用户名、密码和身份验证数据库以对用户进行身份验证。

Note

Starting in MongoDB version 4.0, MongoDB removes support for the deprecated MongoDB Challenge-Response (MONGODB-CR) authentication mechanism.从MongoDB 4.0版本开始,MongoDB删除了对不推荐使用的MongoDB Challenge Response(MongoDB-CR)身份验证机制的支持。

If you are connecting to your deployment using TLS/SSL or an SSH tunnel, refer to the following tabs for specific instructions:如果使用TLS/SSL或SSH隧道连接到部署,请参阅以下选项卡以获取具体说明:

This option directs MongoDB for VS Code to connect to your MongoDB deployment via TLS/SSL. 此选项指示MongoDB for VS Code通过TLS/SSL连接到您的MongoDB部署。You can select one of the following SSL options:您可以选择以下SSL选项之一:

Option选项Description描述
System CA/Atlas Deployment系统CA/Atlas部署Connect to MongoDB Atlas.连接到MongoDB Atlas
Server Validation服务器验证MongoDB for VS Code validates the identity of the deployment. MongoDB for VS Code验证部署的身份。If selected, you must provide:如果选中,则必须提供:

Certificate Authority证书颁发机构One 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 MongoDB for VS Code validates the identity of the deployment. 部署从其客户端执行证书验证,MongoDB for VS Code验证部署的标识。If selected, you must provide:如果选中,则必须提供:

Certificate Authority File证书颁发机构文件One or more certificate files from trusted Certificate Authorities to validate the certificate provided by the deployment.来自受信任证书颁发机构的一个或多个证书文件,用于验证部署提供的证书。
Client Certificate客户端证书A TLS/SSL certificate to present to the deployment to verify the identity of the connecting client. 向部署提供TLS/SSL证书,以验证连接客户端的身份。Typical file extensions for the certificate are .crt or .pem.证书的典型文件扩展名是.crt.pem
Client Private Key客户端私钥A TLS/SSL key file to the deployment to verify the identity of the connecting client. 部署的TLS/SSL密钥文件,用于验证连接客户端的标识。Typical file extensions for the private key are .key or .pem.私钥的典型文件扩展名是.key.pem
Client Key Password客户端密钥密码If 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.使用TLS/SSL而不进行任何身份验证。
Tip

For production use, your MongoDB deployment should use valid certificates generated and signed by a single certificate authority. 对于生产使用,您的MongoDB部署应该使用由单个证书颁发机构生成和签名的有效证书。You or your organization can generate and maintain an independent certificate authority, or use certificates generated by a third-party TLS/SSL vendor.您或您的组织可以生成和维护独立的证书颁发机构,也可以使用第三方TLS/SSL供应商生成的证书。

This option directs MongoDB for VS Code to connect to your MongoDB deployment via an SSH tunnel. The tunnel automatically starts when you connect to MongoDB and stops when you disconnect.此选项指示MongoDB for VS Code通过SSH隧道连接到您的MongoDB部署。当您连接到MongoDB时,隧道会自动启动,当您断开连接时会停止。

In the SSH Tunnel dropdown, choose either a password or an identity file to provide authentication. 在“SSH隧道”下拉列表中,选择密码或身份文件以提供身份验证。Once you select your identification method, specify the following options:选择识别方法后,请指定以下选项:

SSH HostnameEnter the bastion (jumpbox) hostname. 输入bastion(jumpbox)主机名。This is the unique identifier (Fully Qualified Domain Name, or FQDN) for the machine to be accessed.这是要访问的计算机的唯一标识符(完全限定域名或FQDN)。
SSH Tunnel PortProvide the port used for the SSH connection. 提供用于SSH连接的端口。This defaults to 22, the standard port for SSH.默认值为22,这是SSH的标准端口。
SSH UsernameThe username of the profile to log into on the remote system. 要在远程系统上登录的配置文件的用户名。This will be the user for which you want to establish the SSH connection.这将是您要为其建立SSH连接的用户。
SSH Identity FileSelect the file from which the identity (private key) for SSH public key authentication is read.选择从中读取SSH公钥身份验证标识(私钥)的文件。
Unix or OS X: If using OpenSSH, identity files are found in the ~/.ssh directory. Unix或OS X:如果使用OpenSSH,则在~/.ssh目录中可以找到标识文件。By default, the private key files have one of the following file names:默认情况下,私钥文件具有以下文件名之一:

  • id_dsa
  • id_ecdsa
  • id_ed25519
  • id_rsa

On Windows, the location of the identify files depends on your choice of SSH client, such as PuTTY.在Windows上,标识文件的位置取决于您选择的SSH客户端,例如PuTTY。

SSH PassphraseIf your private key is encrypted, provide the passphrase used to decrypt your private key (stored in the specified identity file). 如果您的私钥已加密,请提供用于解密私钥的密码短语(存储在指定的身份文件中)。A passphrase provides an extra layer of security for an SSH connection.密码短语为SSH连接提供了额外的安全层。
SSH PasswordThe password used to secure the SSH connection. 用于保护SSH连接的密码。This is required if you are not using an identity file.如果您没有使用标识文件,则需要执行此操作。

To use an SSH tunnel through a bastion host, the SSH configuration on the bastion host must allow TCP port forwarding; i.e., the AllowTcpForwarding directive in the /etc/ssh/sshd_config file is set to yes. 要使用通过堡垒主机的SSH隧道,堡垒主机上的SSH配置必须允许TCP端口转发;也就是说,/etc/ssh/sshd_config文件中的AllowTcpForwarding指令被设置为yesIf AllowTcpForwarding is not set to yes, set to yes and restart the SSH daemon (sudo service sshd restart).如果AllowTcpForwarding未设置为yes,请设置为yes并重新启动SSH守护进程(sudo服务sshd重新启动)。

Instead of creating the SSH tunnel using MongoDB for VS Code, you can also create the tunnel manually from the command line:您也可以从命令行手动创建隧道,而不是使用MongoDB for VS Code创建SSH隧道:

ssh -L <local_port>:<mongodb_hostname>:<mongodb_port> \
<user>@<bastion_hostname> -fN
Example

If you have a deployment running on hostname-a.com on port 27017, and the bastion host is hostname-b.com with user name ec2-user, you can build the tunnel via如果您在端口27017上的hostname-a.com上运行部署,并且bastion主机是hostname-b.com,用户名为ec2-user,则可以通过

ssh -L 27000:hostname-a.com:27017 ec2-user@hostname-b.com -fN

Using this SSH tunnel, you can now connect MongoDB for VS Code (or the mongo shell) to localhost:27000 to connect to the deployment running on hostname-a.com.使用这个SSH隧道,您现在可以将MongoDB for VS Code(或mongo shell)连接到localhost:27000,以连接到在主机名acom上运行的部署。

Note

You cannot connect to a replica set via an SSH tunnel. 您无法通过SSH隧道连接到复制副本集MongoDB for VS Code cannot establish a connection to multiple servers across the same SSH tunnel.MongoDB for VS Code无法通过同一SSH隧道建立到多个服务器的连接。

5

Optional: Specify read preference in the Advanced tab.可选:在“高级”选项卡中指定读取首选项。

You can select the Read Preference, which specifies how MongoDB for VS Code directs read operations. Options are:您可以选择“读取首选项”,它指定MongoDB for VS Code如何指导读取操作。选项包括:

Read Preference Mode读取首选项模式Description描述
PrimaryDefault mode. 默认模式。All operations read from the current replica set primary.从当前复制副本集主副本读取的所有操作。
Primary PreferredIn most situations, operations read from the primary but if it is unavailable, operations read from secondary members.在大多数情况下,操作从主成员读取,但如果主成员不可用,则操作从辅助成员读取。
SecondaryAll operations read from the secondary members of the replica set.从复制副本集的辅助成员读取的所有操作。
Secondary PreferredIn most situations, operations read from secondary members but if no secondary members are available, operations read from the primary.在大多数情况下,操作从次要成员读取,但如果没有可用的次要成员,则操作从主要成员读取。
NearestOperations 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.要了解有关阅读首选项的更多信息,请参阅阅读首选项

6

Click Connect.单击“连接”。

Activate a Connection激活连接

You can connect MongoDB for VS Code to only one deployment at a time. 一次只能将MongoDB for VS Code连接到一个部署。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 view in the Activity Bar.在Visual Studio Code中,单击“活动栏”中的“MongoDB”视图。

2

Right-click the connection you want to activate, then click Connect.右键单击要激活的连接,然后单击“连接”。

Launch MongoDB Shell启动MongoDB Shell

You can connect the MongoDB Shell or legacy mongo shell to your active deployment.您可以将MongoDB Shell或遗留的mongo Shell连接到您的活动部署。

Considerations注意事项

  • The shell that MongoDB for VS Code uses to connect to your deployment is determined by the Shell setting in your extension settings. MongoDB for VS Code用于连接到部署的shell由扩展设置中的shell设置决定。You can choose either the MongoDB Shell or the legacy mongo shell.您可以选择MongoDB Shell或传统的mongo Shell。
  • The path to your selected shell must exist in your system's PATH. 所选shell的路径必须存在于系统的PATH中。If it does not exist in your PATH, the operation errors.如果它不存在于您的PATH中,则操作将出错。

Procedure程序

To connect the shell to your active deployment:要将shell连接到活动部署,请执行以下操作:

  1. In the MongoDB for VS Code Connections list, right-click your active deployment.在MongoDB for VS Code“连接”列表中,右键单击您的活动部署。
  2. Select Launch MongoDB Shell.选择“Launch MongoDB Shell”。

MongoDB for VS Code opens the Terminal window in VS Code and launches the shell connected to your selected deployment.MongoDB for VS Code打开VS Code中的“终端”窗口,并启动连接到所选部署的shell。

Rename a Connection重命名连接

To rename a connection to a deployment in MongoDB for VS Code:要在MongoDB for VS Code中重命名与部署的连接,请执行以下操作:

1

In Visual Studio Code, click the MongoDB view in the Activity Bar.在Visual Studio Code中,单击“活动栏”中的MongoDB视图。

2

Right-click the connection you want to activate, then click Rename Connection.右键单击要激活的连接,然后单击“重命名连接”。

3

Rename the connection.重命名连接。

  1. In the Command Palette, type a new name for the connection.在命令面板中,键入连接的新名称。
  2. Press the Enter or Return key to rename the connection.EnterReturn键重命名连接。

Disconnect from a Deployment断开与部署的连接

MongoDB for VS Code provides two methods to disconnect from a deployment. You can:MongoDB for VS Code提供了两种从部署断开连接的方法。您可以:

  • Disconnect with the Command Palette, or断开与命令面板的连接,或
  • Disconnect from the MongoDB view in the Activity Bar.从“活动栏”中的MongoDB视图断开连接。
1

In Visual Studio Code, open the Command Palette.在Visual Studio Code中,打开“命令面板”。

Operating System操作系统Method方法Actions操作
AnyVisual Studio Code MenuView > Command Palette
MacOSKeyboard ShortcutPress Command + Shift + P
Windows and LinuxKeyboard ShortcutPress Control + Shift + P
2

Disconnect.断开。

  1. From the Command Palette, select MongoDB: Disconnect.从命令调色板中,选择“MongoDB:断开”。

    Tip

    Enter mongodb in the Command Palette to display all of the MongoDB for VS Code commands you can use.在命令调色板中输入mongodb,以显示所有可以使用的mongodb for VS Code命令。

  2. Press Enter.Enter键。
1

In Visual Studio Code, click the MongoDB view in the Activity Bar.在Visual Studio Code中,单击“活动栏”中的MongoDB视图。

2

Right-click the deployment from which you want to disconnect, then click Disconnect.右键单击要断开连接的展开,然后单击“断开连接”。

Disconnecting from a MongoDB instance closes the MongoDB for VS Code connection to the active instance. 断开与MongoDB实例的连接将关闭与活动实例的MongoDB for VS Code连接。You must reconnect to interact with data in your deployment again.必须重新连接才能再次与部署中的数据交互。

Remove a Connection删除连接

MongoDB for VS Code provides two methods to remove a connection to a deployment from Visual Studio Code. You can:MongoDB for VS Code提供了两种方法来从Visual Studio Code中删除到部署的连接。您可以:

  • Remove a connection with the Command Palette, or删除与命令面板的连接,或
  • Remove a connection from the MongoDB view in the Activity Bar.从“活动栏”的MongoDB视图中删除连接。
Important

Removing a connection from Visual Studio Code removes it both from the current workspace and from Visual Studio Code globally.从Visual Studio Code中删除连接会将其从当前工作区和Visual Studio Code全局删除。

1

In Visual Studio Code, open the Command Palette.在Visual Studio Code中,打开“命令面板”。

Operating System操作系统Method方法Actions操作
AnyVisual Studio Code MenuView > Command Palette
MacOSKeyboard ShortcutPress Command + Shift + P
Windows and LinuxKeyboard ShortcutPress Control + Shift + P
2

From the Command Palette, select MongoDB: Remove Connection....从命令调色板中,选择“MongoDB:删除连接...”。

Tip

Enter mongodb in the Command Palette to display all of the MongoDB for VS Code commands you can use.在命令调色板中输入mongodb,以显示所有可以使用的mongodb for VS Code命令。

If you have more than one connection, select the connection you want to remove from the Command Palette.如果有多个连接,请从命令面板中选择要删除的连接。

3

Click Yes to remove the connection.单击“是”删除连接。

1

In Visual Studio Code, click the MongoDB view in the Activity Bar.在Visual Studio Code中,单击“活动栏”中的“MongoDB”视图。

2

Right-click the connection you want to remove, then click Remove Connection.右键单击要删除的连接,然后单击“删除连接”。

3

Click Yes to remove the connection.单击“是”删除连接。