Docs Home / VS Code Extension / Reference

Visual Studio Code CommandsVisual Studio Code命令

This document lists the VS Code commands available for VS Code Extension. To open the Command Palette and execute these commands:本文档列出了可用于VS Code扩展的VS Code命令。要打开命令面板并执行以下命令:

Operating System操作系统Method方法Actions操作
AnyVisual Studio Code Menu菜单View > Command Palette视图>命令选项板
MacOSKeyboard Shortcut键盘快捷键Press Command + Shift + P
Windows and LinuxKeyboard Shortcut键盘快捷键Press Control + Shift + P

Tip

Enter mongodb in the Command Palette to display all of the VS Code Extension commands you can use.在命令面板中输入mongodb以显示可以使用的所有VS Code扩展命令。

Connection Commands连接命令

Run these commands from the Command Palette to create new connections or manage existing connections to your MongoDB deployments.从命令面板运行这些命令,以创建新连接或管理与MongoDB部署的现有连接。

Configuring a new connection adds a new entry to your Connections list in the VS Code Extension view. Select a connection from the list to activate that connection.配置新连接会在VS Code扩展视图中的连接列表中添加一个新条目。从列表中选择一个连接以激活该连接。

To learn more about connecting to a deployment, see Connect to Your MongoDB Deployment.要了解有关连接到部署的更多信息,请参阅连接到MongoDB部署

Note

You can configure multiple connections, but only have one active connection open at a time.您可以配置多个连接,但一次只能打开一个“活动”连接。

Command命令Description描述
Connect连接Connect to your MongoDB deployment by filling in your connection information in the connection dialog.通过在连接对话框中填写连接信息来连接到MongoDB部署。
Connect with Connection String使用连接字符串连接

Connect to your MongoDB deployment by pasting your connection string URI directly into the command palette. Connecting to a deployment adds a new entry to your Connections list in the VS Code Extension view.通过将连接字符串URI直接粘贴到命令面板中,连接到MongoDB部署。连接到部署会在VS Code扩展视图中的“连接”列表中添加一个新条目。

Atlas provides a connection string for your clusters which you can pass into this command.Atlas为集群提供了一个连接字符串,您可以将其传递到此命令中。

Disconnect断开连接

Disconnect from your active deployment connection.断开与活动部署连接的连接。

Remove Connection删除连接

Select and remove a connection from your list of connections in VS Code Extension.在VS Code扩展中从连接列表中选择并删除连接。

Removing your current active connection also closes that connection.删除当前活动连接也会关闭该连接。

Shell Commandsshell命令

Run this command from the Command Palette to open a MongoDB Shell connected to your deployment.从命令面板运行此命令,打开连接到部署的MongoDB Shell。

Command命令Description描述

Launch MongoDB Shell启动MongoDB Shell

IMPORTANT:重要: This command is not supported on Windows.Windows不支持此命令。

Open the VS Code Terminal and automatically connect a MongoDB shell to the deployment specified in your active connection.打开VS Code“终端”,自动将MongoDB shell连接到活动连接中指定的部署。

Specify the MongoDB shell to use in the mdb.shell setting. VS Code Extension supports the following shells:指定要在mdb.shell设置中使用的MongoDB shell。VS Code扩展支持以下shell:

  • Legacy 遗留的mongo shell
  • mongosh shell.

To launch your selected MongoDB shell, you must:要启动所选的MongoDB shell,您必须:

  • Install the shell you want to use, and安装要使用的shell,然后
  • Configure your machine's PATH environment variable to include the filepath to your shell binary.配置计算机的PATH环境变量,以包含shell二进制文件的文件路径。

If you install a new version of your MongoDB shell, you will need to update your PATH variable to reference the new version.如果安装新版本的MongoDB shell,则需要更新PATH变量以引用新版本。

Playground Commands游乐场命令

Run these commands from the Command Palette to create and run playgrounds.从命令选项板运行这些命令以创建和运行游乐场

Command命令Description描述

Create MongoDB Playground创建MongoDB游乐场

Create a new playground to run against your MongoDB deployment.创建一个新的游乐场来运行你的MongoDB部署。

By default, playgrounds load with a template containing sample commands. You can disable this template from your extension settings.默认情况下,游乐场加载包含示例命令的模板。您可以从扩展设置中禁用此模板。

Run All From Playground从游乐场运行一切

Run file you are currently viewing in VS Code as a playground. Your playground runs against the deployment specified in your active connection.将您当前在VS Code中查看的文件作为游乐场运行。游乐场与活动连接中指定的部署相反。

VS Code Extension splits your playground window to display the results in a pane titled Playground Results.json to the right of your playground. VS Code Extension拆分游乐场窗口,在游乐场右侧名为“游乐场Results.json”的窗格中显示结果。If you disabled split-view for your VS Code Editor window, VS Code Extension displays the playground results in a new tab to the right of your playground. 如果禁用了VS Code编辑器窗口的拆分视图,VS Code扩展将在游乐场右侧的新选项卡中显示游乐场结果。If you manually move your playground results, VS Code Extension displays the results in that tab.如果手动移动操场结果,VS Code扩展将在该选项卡中显示结果。

VS Code Extension View CommandsVS Code扩展视图命令

Run these commands from the Command Palette to manage the VS Code Extension view in the left navigation panel.从命令面板运行这些命令,以管理左侧导航面板中的VS Code扩展视图。

Command命令Description描述
Focus on MongoDB View关注MongoDB视图Open and focus on the VS Code Extension view.打开并专注于VS Code扩展视图。
Show MongoDB显示MongoDB

If VS Code Extension is hidden from your extension view, show it.如果VS Code扩展在扩展视图中隐藏,请显示它。

MongoDB MCP Server CommandsMongoDB MCP服务器命令

Run these commands from the Command Palette to manage the MongoDB MCP server.从命令面板运行这些命令来管理MongoDB MCP服务器

Command命令Description描述
Start MCP Server启动MCP服务器

Manually starts the MCP server if it isn't already running.如果MCP服务器尚未运行,请手动启动它。

By default, you must explicitly start the MCP server. 默认情况下,您必须显式启动MCP服务器。To enable automatic startup, set the mdb.mcp.server setting to autoStartEnabled.要启用自动启动,请将mdb.mcp.server设置设置为autoStartEnabled

Stop MCP Server停止MCP服务器

Stops the MCP server.停止MCP服务器。

Stopping the MCP server using this command is not enough to prevent the MCP server from automatically starting on the next editor restart. 使用此命令停止MCP服务器不足以阻止MCP服务器在下次编辑器重新启动时自动启动。To disable automatic startup, you must also configure the mdb.mcp.server setting in the VS Code Extension settings.要禁用自动启动,您还必须在VS Code扩展设置中配置mdb.mcp.server设置。

Get MCP Server Config获取MCP服务器配置

Opens a temporary JSON file containing the current URL and security headers needed to connect to the MCP server.打开一个临时JSON文件,其中包含连接到MCP服务器所需的当前URL和安全标头。

To learn more about configuring the MongoDB MCP server, see MongoDB MCP Server Configuration.要了解有关配置MongoDB MCP服务器的更多信息,请参阅MongoDB MCP服务器配置