> 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: playground-panel, mdboverview, command-palette
-->

# Explore Your Data with Playgrounds

MongoDB Playgrounds are JavaScript environments where you can prototype queries, aggregations, and MongoDB commands with helpful syntax highlighting.

MongoDB Playgrounds provide intelligent autocomplete for:

- The Mongo Shell API (Application Programming Interface)

- MongoDB keywords, operators, aggregation stages, database, collection, and field names.

- Any JavaScript variables or keywords.

You can save playgrounds in your workspace and use them to document how your application interacts with MongoDB. VS Code Extension interprets files with the `.mongodb.js` extension as playgrounds.

Starting in version `0.11.0` the default file extension for MongoDB Playgrounds files is `.mongodb.js`. Previous versions of MongoDB Playgrounds use the default file extension `.mongodb`. MongoDB Playgrounds support both file extensions.

**Note:**

You can also use your application to perform CRUD operations on documents using the appropriate [driver](https://www.mongodb.com/docs/drivers/). Playgrounds are meant to help you prototype database operations as you develop your application.

VS Code Extension splits your Playground window to display your Playground Result in the right-side pane. You can perform one of two actions on the result depending on the query you ran in the Playground.

- You may save *any* Playground Result to a file.

- You may edit any JSON (Javascript Object Notation) document that VS Code Extension returns in the Playground Result from a [findOne or find query.](https://www.mongodb.com/docs/mongodb-vscode/read-document-playground.md)

  VS Code Extension returns these results in JSON (Javascript Object Notation) format with JSON (Javascript Object Notation) syntax highlighting. Each JSON (Javascript Object Notation) document has an Edit Document link at its top.

  1. Click Edit Document at the top of the document you want to edit.

     VS Code Extension opens this one JSON (Javascript Object Notation) document in a new window as an editable document.

  2. Make any changes you need.

  3. Press Ctrl+S (Cmd+S on macOS) to save those changes in the database.

## Prerequisite

To run a playground, you must connect to a MongoDB deployment using VS Code Extension. To learn how to connect to a deployment, see either:

- [Connect to Your MongoDB Deployment](https://www.mongodb.com/docs/mongodb-vscode/connect.md#std-label-vsce-connect)

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

## Open a Playground

### Create a New Playground

You can create a new playground from the Playgrounds panel, the VS Code Extension *Overview* page, or the [Microsoft Visual Studio Code](https://code.visualstudio.com/) Command Pallette.

### Playgrounds Panel

If you have no saved playgrounds in your Visual Studio Code workspace, in the Playgrounds panel of VS Code Extension, click Create New Playground.

![Image of Create New Playground button](/images/vsce-create-new-playground.png)

If you have saved playgrounds in your [Microsoft Visual Studio Code](https://code.visualstudio.com/) workspace, click the ... menu icon of the Playgrounds panel and select Create MongoDB Playground.

**Note:**

You can also open a new playground to test and export queries with the [MongoDB Extension for Github Copilot](https://www.mongodb.com/docs/mongodb-vscode/copilot.md#std-label-vsce-copilot). For more information, see [Export and Test Queries with Copilot.](https://www.mongodb.com/docs/mongodb-vscode/copilot-export-test.md#std-label-vsce-test-queries-copilot)

### Open a Saved Playground

If you have files in your Visual Studio Code workspace with the `.mongodb.js` or `.mongodb` extension, VS Code Extension displays these files in the Playgrounds panel.

Double click a file to open that playground.

## Run a Playground

To run a playground, click the Play Button in VS Code's top navigation bar. Your playground runs against the deployment specified in your [active connection.](https://www.mongodb.com/docs/mongodb-vscode/connect.md#std-label-vsce-connect)

### Connect to a Deployment from a Playground

If VS Code Extension is not connected to a MongoDB deployment, you can specify a connection string for the deployment you want to run your playground against.

If you have a playground file open in Visual Studio Code and do not have an active connection, VS Code Extension displays Click here to add connection at the top of your playground.

1. Select Click here to add connection

   After you click Click here to add connection, VS Code Extension displays the connection string drop-down menu.

   ![Link to add connection from playground](/images/vsce-playground-add-connection-btn.png)

2. Click Add new connection

   In the connection string drop-down menu, select Add new connection to enter a new connection string. If you have previously connected to the playground with another deployment, the connection string will appear as an option under the drop-down menu.

3. Enter your connection string

   Enter the [connection string](https://www.mongodb.com/docs/manual/reference/connection-string/) to connect to your deployment.

   **Note:**

   If the connection string specifies a database the playground runs against that database by default. To switch databases, call `use('<database_name>')`.

   If you are connected to a default database, the playground autocompletes only for collection names available on that database.

4. Press Enter

   After you enter your connection string, a [CodeLens](https://code.visualstudio.com/blogs/2017/02/12/code-lens-roundup) replaces the Click here to add connection link. The CodeLens includes information on the connected deployment and, if applicable, the current database.

5. Run your playground

**Note:**

When you connect to a deployment through the playground connection dialog, that connection is added to your VS Code Extension Connections list.

### Run Selected Lines of a Playground

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.

VS Code Extension shows the Run Selected Lines from Playground link immediately above your selected section. Click this link to test and troubleshoot specific lines or sections of your playground.

## Code Formatting and Linting Tools

MongoDB Playgrounds are JavaScript files and can work with popular Visual Studio Code formatting and linting extensions like [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) and [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint).

If you use a code formatting extension, MongoDB Playgrounds suggest autocompletion and linting hints for:

- System variables such as `$$ROOT` and `$$NOW`

- `use` and `db` commands

- Collection names, in bracketed notation such as `db["collection"].find({})`

- Alternative commands for shell commands not supported in MongoDB Playgrounds such as `show users`

For a full list of autocompletion and linting improvements, see the [v0.11.1 release notes](https://github.com/mongodb-js/vscode/releases/tag/v0.11.1).

## Log to Console from a Playground

VS Code Extension supports the following methods to log messages to the console. Logged messages appear in the Output panel in VSCode.

- `console.log()`

- `print()`

- `printjson()`

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.

## Tutorials

- To learn how to use MongoDB Playgrounds for CRUD operations, see [Perform CRUD Operations with VS Code.](https://www.mongodb.com/docs/mongodb-vscode/crud-ops.md#std-label-vsce-crud)

- To learn how to use MongoDB Playgrounds to run aggregation pipelines, see [Run Aggregation Pipelines with VS Code.](https://www.mongodb.com/docs/mongodb-vscode/run-agg-pipelines.md#std-label-vsce-aggregation)

## Consideration for Authentication

If your deployment requires authentication, your [database user privileges](https://www.mongodb.com/docs/manual/reference/privilege-actions.md#std-label-security-user-actions) may affect the actions you can perform using VS Code Extension.
