Navigation

    Explore Your Data with Playgrounds

    Info With Circle IconCreated with Sketch.Note
    Preview

    MongoDB for VS Code is currently available as a Preview in the 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 Playgrounds provide intelligent autocomplete for:

    • The Mongo Shell API ,
    • MongoDB operators,
    • Database, collection, and field names.

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

    Info With Circle IconCreated with Sketch.Note

    You can also use your application to perform CRUD operations on documents using the appropriate driver. Playgrounds are meant to help you prototype database operations as you develop your application.

    MongoDB for VS Code splits your Playground window to display the results of your Playground in JSON format in the right-side pane labeled Playground Results.json. If you disabled split-view, MongoDB for VS Code displays the Playground results in JSON format in a new tab to the right of your Playground. You cannot edit the results in the results pane. You can save the results to a file.

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

    You can create a new playground from the Playgrounds panel, the MongoDB for VS Code Overview page, or the Microsoft Visual Studio Code Command Pallette.

    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.

    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.

    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.

    Double click a .mongodb file to open that 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.

    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.

    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.

    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.
    4. Run your playground.
    Info With Circle IconCreated with Sketch.Note

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

    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. 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. 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.

    If your deployment requires authentication, your database user privileges may affect the actions you can perform using MongoDB for VS Code.

    Give Feedback