Docs HomeMongoDB for VS Code

MongoDB for VS Code Commands用于VS Code命令的MongoDB

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

Operating System操作系统Method方法Actions操作
AnyVisual Studio Code MenuView > Command Palette
MacOSKeyboard ShortcutPress Command + Shift + P
Windows and LinuxKeyboard ShortcutPress Control + Shift + P
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命令。

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 MongoDB for VS Code view. 配置一个新连接会在MongoDB for VS Code视图中为“连接”列表添加一个新条目。Select a connection from the list to activate that connection.从列表中选择一个连接以激活该连接。

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. 通过将连接字符串URI直接粘贴到命令面板中,连接到MongoDB部署。Connecting to a deployment adds a new entry to your Connections list in the MongoDB for VS Code view.连接到部署会在MongoDB for VS Code视图中的Connections列表中添加一个新条目。
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 MongoDB for VS Code.在MongoDB for VS Code中,从连接列表中选择并删除一个连接。
Note

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外壳连接到活动连接中指定的部署。
Specify the MongoDB shell to use in the mdb.shell setting. 指定要在mdb.shell设置中使用的MongoDB shell。MongoDB for VS Code supports the following shells:MongoDB for VS Code支持以下shell:

  • Legacy mongo shell遗留的mongo shell
  • mongosh shell.
Important

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变量以引用新版本。

Tip

See also:

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. 将您当前在VS Code中查看的运行文件作为演练场。Your playground runs against the deployment specified in your active connection.您的演练场与活动连接中指定的部署背道而驰。
MongoDB for VS Code splits your playground window to display the results in a pane titled Playground Results.json to the right of your playground. MongoDB for VS Code拆分您的演练场窗口,在演练场右侧标题为Playground Results.json的窗格中显示结果。If you disabled split-view for your VS Code Editor window, MongoDB for VS Code displays the playground results in a new tab to the right of your playground. 如果您禁用了VS Code编辑器窗口的拆分视图,MongoDB for VS Code会在演练场右侧的新选项卡中显示演练场结果。If you manually move your playground results, MongoDB for VS Code displays the results in that tab.如果手动移动演练场结果,MongoDB for VS Code会在该选项卡中显示结果。

MongoDB for VS Code View CommandsMongoDB for VS Code视图命令

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

Command命令Description描述
Focus on MongoDB View关注MongoDB视图Open and focus on the MongoDB for VS Code view.打开并关注MongoDB for VS Code视图。
Show MongoDBIf MongoDB for VS Code is hidden from your extension view, show it.如果MongoDB for VS Code在您的扩展视图中是隐藏的,请显示它。