Home

Awesome

MongoDB for VS Code

Build Status

MongoDB for VS Code makes it easy to work with your data in MongoDB directly from your VS Code environment. MongoDB for VS Code is the perfect companion for MongoDB Atlas, but you can also use it with your self-managed MongoDB instances.

<p align="center"> <a title="Watch the MongoDB for VS Code demo video" href="https://mdb.link/vs-code-demo-video"> <img src="https://github.com/mongodb-js/vscode/raw/main/resources/screenshots/get-started.png" width="700" alt="MongoDB for VS Code demo video call to action"> </a> </p>

Features

Navigate your MongoDB Data

Read more about this functionality in the online documentation.

Explore data with MongoDB for VS Code

MongoDB Playgrounds

MongoDB Playgrounds are the most convenient way to prototype and execute CRUD operations and other MongoDB commands directly inside VS Code.

Playgrounds

Note: Make sure you are connected to a server or cluster before using a playground. You can't run a playground and you won't get intelligent completions if you are not connected.

From Query API to your favorite language

Select queries and aggregations within your Playground files and translate them into your favorite programming language. Supported languages are:

Export to language

Document Editing

Editing documents with MongoDB for VS Code is as natural as editing any file in the code editor. Open a document in an editor tab, edit it, and save the changes back to MongoDB.

Document editing

Quick access to the MongoDB Shell

Launch the MongoDB Shell from the command palette to quickly connect to the same cluster you have active in VS Code.

MongoDB Shell

Note: The mongosh binary needs to be in your $PATH. You can download the mongosh from the MongoDB Download Center.

Terraform snippet for MongoDB Atlas

If you use Terraform to manage your infrastructure, MongoDB for VS Code helps you get started with the MongoDB Atlas Provider. Just open a Terraform file, type atlas and you are good to go.

Terraform snippet

Atlas Stream Processing

Connect to Atlas Stream Processing instances and develop stream processors using playgrounds.

Atlas Stream Processing Playground

MongoDB Copilot Participant

Use natural language to interact with your clusters and generate MongoDB-related code with GitHub Copilot Chat in VS Code.

Note: To use the MongoDB Participant, you must have the GitHub Copilot extension. By using Copilot Chat you agree to GitHub Copilot chat preview terms. Find more details about the MongoDB GenAI Features in the FAQ.

How to use the MongoDB Participant

  1. Enter @MongoDB in the chat input field to start a conversation with the MongoDB Participant.

MongoDB Participant

  1. Start typing / in the chat window to get the list of available chat participant commands.

MongoDB Participant Commands

Extension Settings

SettingDescriptionDefault
mdb.shellThe MongoDB shell to use ( mongosh or the legacy mongo ).mongosh
mdb.showMongoDBConnectionExplorerShow or hide the MongoDB Connection explorer.true
mdb.showMongoDBPlaygroundsShow or hide the MongoDB Playgrounds explorer.true
mdb.showMongoDBHelpExplorerShow or hide the MongoDB Help panel.true
mdb.defaultLimitThe number of documents to fetch when viewing documents from a collection.10
mdb.confirmRunAllShow a confirmation message before running commands in a playground.true
mdb.confirmRunCopilotCodeShow a confirmation message before running code generated by the MongoDB participant.true
mdb.useSampleDocsInCopilotEnable sending sample field values with the VSCode copilot chat @MongoDB participant /query command.false
mdb.confirmDeleteDocumentShow a confirmation message before deleting a document in the tree view.true
mdb.persistOIDCTokensRemain logged in when using the MONGODB-OIDC authentication mechanism for MongoDB server connection. Access tokens are encrypted using the system keychain before being stored.true
mdb.showOIDCDeviceAuthFlowOpt-in and opt-out for diagnostic and telemetry collection.true
mdb.browserCommandForOIDCAuthCommand to be used as browser for facilitating OIDC auth redirects""
mdb.excludeFromPlaygroundsSearchExclude files and folders while searching for playground files in the current workspace.Refer to package.json
mdb.connectionSaving. defaultConnectionSavingLocationWhen the setting that hides the option to choose where to save new connections is checked, this setting sets if and where new connections are saved.Global
mdb.useDefaultTemplateForPlaygroundChoose whether to use the default template for playground files or to start with an empty playground editor.true
mdb.uniqueObjectIdPerCursorThe default behavior is to generate a single ObjectId and insert it on all cursors. Set to true to generate a unique ObjectId per cursor instead.false
mdb.sendTelemetryOpt-in and opt-out for diagnostic and telemetry collection.true
mdb.confirmRunCopilotCodeShow a confirmation message before running code generated by the MongoDB participant.true
mdb.useSampleDocsInCopilotEnable sending sample field values with the VSCode copilot chat @MongoDB participant /query command.false

Additional Settings

Autocomplete

Note: these global settings affect how MongoDB for VS Code provides intelligent autocomplete inside snippets and string literals (off by default). Changing the default configuration may affect the behavior and performance of other extensions and of VS Code itself. If you do not change the default settings, you can still trigger intelligent autocomplete inside a snippet or string literal with Ctrl+Space.

"editor.quickSuggestions": {
  "other": true,
  "comments": false,
  "strings": true
}

Syntax Highlighting

MongoDB playgrounds are JavaScript files, which causes JavaScript syntax highlighting to override any customizations made to the MongoDB syntax colors.

Currently, there is no way to resolve this except for turning off semantic highlighting for a current workspace, or for all themes that are being used by setting editor.semanticHighlighting.enabled to false.

Telemetry

MongoDB for VS Code collects usage data and sends it to MongoDB to help improve our products and services. Read our privacy policy to learn more. If you don’t wish to send usage data to MongoDB, you can opt-out by setting mdb.sendTelemetry to false in the extension settings.

Contributing

For issues, please create a ticket in our JIRA Project.

For contributing, please refer to CONTRIBUTING.md.

Is there anything else you’d like to see in MongoDB for VS Code? Let us know by submitting suggestions in our feedback forum.

Building and Installing from Source

You can clone this repository and install the extension in your VS Code with:

npm install
npm run local-install

This will compile and package MongoDB for VS Code into a .vsix file and add the extension to your VS Code.

To install this locally on Windows:

npm install
.\node_modules\.bin\vsce.cmd package
code --install-extension ./mongodb-vscode-*.vsix

This will compile and package MongoDB for VS Code into a .vsix file and add the extension to your VS Code.

If you get an error because the code command is not found, you need to install it in your $PATH.

Open VS Code, launch the Command Palette (⌘+Shift+P on macOS, Ctrl+Shift+P on Windows and Linux), type code and select "Install code command in $PATH".

License

Apache 2.0