Rock Mountain
  • Home
  • User Guide
    • Glass Web Components
    • Using reCAPTCHA
    • Publishing Source Code with Syntax Highlighting
  • Developer Guide
    • Getting Started
    • Adding NPM Packages
    • Database
      • Backing Up and Restoring Data
      • Database Schema
      • MongoDB Tips and Snippets
      • VS Code and the MongoDB Playground
    • Common Errors and Their Solutions
    • Developing Glass Web Components
    • DevOps
      • Build and Deployment Procedure
      • GitHub Conventions and Workflow
      • Merging Preview Into Main
    • File Structure
    • React Components
      • SiteLayout Component
      • Toggle Lazy Load Image Component
    • Update or Change the Fav Icon
    • References and Learning Resources
  • Icons
Powered by GitBook
On this page
  • Configuring Visual Studio Code for the MongoDB Playground
  • References
  1. Developer Guide
  2. Database

VS Code and the MongoDB Playground

PreviousMongoDB Tips and SnippetsNextCommon Errors and Their Solutions

Last updated 3 years ago

To get the most out of MongoDB, you're going to need to become familiar with the MongoDB Query Language (MQL). No, it is not like SQL if you're familiar with relational database management systems (RDBMS), but it isn't any more difficult. MQL can be used from the CLI, Visual Studio Code, the development drivers, and more. You'll get the same experience no matter where you're trying to write your queries.

In this section, we're going to focus on Visual Studio Code and the extension for managing our data. We're doing this because Visual Studio Code is common developer tooling and it makes for an easy to use experience.

Configuring Visual Studio Code for the MongoDB Playground

While we could write our queries out of the box with Visual Studio Code, we won't be able to interact with MongoDB in a meaningful way until we install the extension.

Within Visual Studio Code, bring up the extensions explorer and search for MongoDB (File > Preferences > Extensions).

Install the official extension with MongoDB as the publisher.

With the extension installed, we'll need to interact with it from within Visual Studio Code. There are a few ways to do this, but we're going to use the command palette.

Open the command pallette (CMD + SHIFT + P, if you're on macOS), and enter MongoDB: Connect into the input box.

You'll be able to enter the information for your particular MongoDB cluster. Once connected, we can proceed to creating a new Playground. If you've already saved your information into the Visual Studio Code extension and need to connect later, you can always enter Show MongoDB in the command pallette and connect.

Assuming we're connected, enter Create MongoDB Playground in the command pallette to create a new file with boilerplate MQL.

See the directory, mongodb-playgorunds/ for existing scripts.

Within Visual Studio Code, you can highlight the MQL inside a script and choose Run Selected Lines From Playground or use the command pallette to run the entire playground (i.e. MongoDB: Run All From Playground). There is also a play button to the top-right of the editor when you have a playground .mongodb file open.

References

MongoDB Playground
MongoDB Playground
Getting Started with Atlas and the MongoDB Query Language (MQL)