Explore Your Data with Playgrounds利用演练场探索你的数据

On this page本页内容

Note
Preview预览

MongoDB for VS Code is currently available as a Preview in the Visual Studio Marketplace.MongoDB for VS Code目前在Visual Studio Marketplace中作为预览版提供。The product, its features, and the corresponding documentation may change during the Preview stage.在预览阶段,产品及其相应的功能可能会发生变化。

MongoDB Playgrounds are JavaScript environments where you can prototype queries, aggregations, and MongoDB commands with helpful syntax highlighting.MongoDB演练场是一个JavaScript环境,您可以在其中利用突出显示的有用的语法创建查询、聚合和MongoDB命令的原型。

MongoDB Playgrounds provide intelligent autocomplete for:MongoDB演练场提供智能自动完成功能:

You can save playgrounds in your workspace and use them to document how your application interacts with MongoDB.您可以在工作区中保存演练场,并使用它们来记录应用程序如何与MongoDB交互。MongoDB for VS Code interprets files with the .mongodb extension as playgrounds.MongoDB for VS Code解释扩展名为.mongodb的文件。

Note

You can also use your application to perform CRUD operations on documents using the appropriate driver.还可以使用应用程序使用适当的驱动程序对文档执行CRUD操作。Playgrounds are meant to help you prototype database operations as you develop your application.演练场旨在帮助您在开发应用程序时对数据库操作进行原型化。

To run a playground, you must connect to a MongoDB deployment using MongoDB for VS Code .要运行演练场,必须使用MongoDB for VS Code连接到MongoDB部署。To learn how to connect to a deployment, see either:要了解如何连接到部署,请参阅:

You can create a new playground from either the Playgrounds panel, or the Microsoft Visual Studio Code Command Pallette.您可以从演练场面板或Microsoft Visual Studio Code命令面板创建新的演练场。

If you have no saved playgrounds in your Visual Studio Code workspace, in the Playgrounds panel of MongoDB for VS Code , click Create New Playground.如果您的Visual Studio Code工作区中没有保存演练场,请在MongoDB for VS Code的“演练场”面板中,单击“创建新演练场”。

Image of Create New Playground button

If you have saved playgrounds in your Microsoft Visual Studio Code workspace, click the ... menu icon of the Playgrounds panel and select Create MongoDB Playground.如果已在Microsoft Visual Studio Code工作区中保存了演练场,请单击Playgrounds面板的...菜单图标并选择“创建MongoDB演练场”。

1

In Visual Studio Code, press one of the following key combinations:在Visual Studio Code中,按以下组合键之一:

  • Control + Shift + P on Windows or Linux.
  • Command + Shift + P on macOS.

The Command Palette provides quick access to commands and keyboard shortcuts.命令板提供对命令和键盘快捷键的快速访问。

2

Use the Command Palette search bar to search for commands.使用命令面板搜索栏搜索命令。All commands related to MongoDB for VS Code are prefaced with MongoDB:.所有与MongoDB for VS Code相关的命令都以MongoDB:起头。

When you run the MongoDB: Create MongoDB Playground command, MongoDB for VS Code opens a playground pre-configured with a few commands.运行MongoDB: Create MongoDB Playground命令时,MongoDB for VS Code会打开一个预先配置了几个命令的演练场。

Note

You can load new Playgrounds without the template by disabling the Use Default Template For Playground setting.通过禁用对演练场使用默认模板设置,可以在不使用模板的情况下加载新的演练场。To learn more about MongoDB for VS Code settings, see MongoDB for VS Code Settings.要了解有关MongoDB for VS Code设置的更多信息,请参阅MongoDB for VS Code设置

If you have files in your Visual Studio Code workspace with the .mongodb extension, MongoDB for VS Code displays these files in the Playgrounds panel.如果Visual Studio Code工作区中有扩展名为.mongodb的文件,则MongoDB for VS Code将在演练场面板中显示这些文件。

Double click a .mongodb file to open that playground.双击.mongodb文件以打开演练场。

To run a playground, click the Play Button in VS Code's top navigation bar.若要运行演练场,点击VSoCode顶部导航栏上的播放按钮Your playground runs against the deployment specified in your active connection.演练场将针对活动连接中指定的部署运行。

If MongoDB for VS Code is not connected to a MongoDB deployment, you can specify a connection string for the deployment you want to run your playground against.如果MongoDB for VS Code未连接到MongoDB部署,则可以为要运行演练场的部署指定连接字符串。

If you have a playground file open in Visual Studio Code and do not have an active connection, MongoDB for VS Code displays Click here to add connection at the top of your playground.如果在Visual Studio Code中打开了一个演练场文件,并且没有活动连接,MongoDB for VS Code会在演练场顶部显示单击此处添加连接。

Link to add connection from playground
  1. Click this link to open the connection string dialog.点击此链接打开连接字符串对话框。
  2. Enter the connection string for the deployment you want to run this playground against.输入要运行此演练场的部署的连接字符串
  3. Press Enter.按下Enter
  4. Run your playground.运行演练场。
Note

When you connect to a deployment through the playground connection dialog, that connection is added to your MongoDB for VS Code Connections list.当您通过演练场连接对话框连接到部署时,该连接将添加到MongoDB for VS Code连接列表中。

If you select a section of your playground, you may optionally run only the selected portion.如果您选择了演练场的一部分,您可以选择只运行选定的部分。You may run either a single line or multiple lines of your playground.你可以在演练场上运行一行或多行。

MongoDB for VS Code shows the Run Selected Lines from Playground link immediately above your selected section.MongoDB forVS Code显示了从演练场运行选定的行的链接,该链接位于所选部分的正上方。Click this link to test and troubleshoot specific lines or sections of your playground.单击此链接可测试和排除演练场的特定行或部分。

MongoDB for VS Code supports the following methods to log messages to the console.MongoDB for VS Code支持以下方法将消息记录到控制台。Logged messages appear in the Output panel in VSCode.记录的消息显示在VS Code的输出面板中。

Logging to the console can be useful to track the output of certain commands in your playground, such as results after a particular query or aggregation.登录到控制台对于跟踪演练场中某些命令的输出非常有用,例如特定查询或聚合之后的结果。

If your deployment requires authentication, your database user privileges may affect the actions you can perform using MongoDB for VS Code .如果部署需要身份验证,则数据库用户权限可能会影响使用MongoDB for VS Code执行的操作。

Navigate Your Data导航数据Perform CRUD Operations执行CRUD操作