diff --git a/docs/azure/images/documentdb/attach-via-connection-string.png b/docs/azure/images/documentdb/attach-via-connection-string.png new file mode 100644 index 0000000000..94dbfde281 --- /dev/null +++ b/docs/azure/images/documentdb/attach-via-connection-string.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:73b05d0c78462f71ff87eeea8a31a219a73a1dec79bcc824de185ef5e64f3df1 +size 10820 diff --git a/docs/azure/images/documentdb/attach-via-service-discovery.png b/docs/azure/images/documentdb/attach-via-service-discovery.png new file mode 100644 index 0000000000..afc7136da8 --- /dev/null +++ b/docs/azure/images/documentdb/attach-via-service-discovery.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e913e6bea763a245d2b90437eea3c0f6cfebf6fd7c0f067c94a4a8ca5dcb67d2 +size 23221 diff --git a/docs/azure/images/documentdb/create-scrapbook.png b/docs/azure/images/documentdb/create-scrapbook.png new file mode 100644 index 0000000000..49cd0475e4 --- /dev/null +++ b/docs/azure/images/documentdb/create-scrapbook.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c1bab65449ffc508693e8362b842a9c0d3234ce635771a3a56b1916f3c24e0b0 +size 31215 diff --git a/docs/azure/images/documentdb/documentdb-explorer.png b/docs/azure/images/documentdb/documentdb-explorer.png new file mode 100644 index 0000000000..51f2bf785c --- /dev/null +++ b/docs/azure/images/documentdb/documentdb-explorer.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1afc59b3d1207d911e90a1ec31e92e662950742b475fd52fa8e930c4fa5578b +size 34979 diff --git a/docs/azure/images/documentdb/install-documentdb-extension.png b/docs/azure/images/documentdb/install-documentdb-extension.png new file mode 100644 index 0000000000..06b7d48181 --- /dev/null +++ b/docs/azure/images/documentdb/install-documentdb-extension.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fac76b705f21b536bf2e85335ec1fec22a92357ea22a3ce614ea7681b3028841 +size 38032 diff --git a/docs/azure/images/documentdb/launch-shell.jpeg b/docs/azure/images/documentdb/launch-shell.jpeg new file mode 100644 index 0000000000..b9d29e5b01 Binary files /dev/null and b/docs/azure/images/documentdb/launch-shell.jpeg differ diff --git a/docs/azure/images/documentdb/manage-database.png b/docs/azure/images/documentdb/manage-database.png new file mode 100644 index 0000000000..7f6b221566 --- /dev/null +++ b/docs/azure/images/documentdb/manage-database.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8fc8d7997a213f028d52c3f1a1e83ceed371c2a2ca03b44f2ff23d7af83e45b5 +size 156109 diff --git a/docs/azure/images/documentdb/run-scrapbook.png b/docs/azure/images/documentdb/run-scrapbook.png new file mode 100644 index 0000000000..d301776389 --- /dev/null +++ b/docs/azure/images/documentdb/run-scrapbook.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:408c8d287c4ce1b715890447952f62f7df7e278fa664f9f8f1e8344a1fd0493a +size 23148 diff --git a/docs/azure/mongodb.md b/docs/azure/mongodb.md index 8bc54046b0..fe8805143d 100644 --- a/docs/azure/mongodb.md +++ b/docs/azure/mongodb.md @@ -1,84 +1,74 @@ --- ContentId: d1187f99-354f-4798-9c19-e432e4ae8572 MetaDescription: Working with MongoDB in Visual Studio Code -DateApproved: 11/1/2022 +DateApproved: 11/1/2025 --- # Working with MongoDB -Visual Studio Code has great support for working with [MongoDB](https://www.mongodb.com/what-is-mongodb) databases, whether your own instance or in [Azure with MongoDB Atlas](https://www.mongodb.com/cloud/atlas/azure-mongodb?utm_campaign=marketplace&utm_source=&utm_medium=marketplace). With the [MongoDB for VS Code](https://marketplace.visualstudio.com/items?itemName=mongodb.mongodb-vscode) extension, you can create, manage, and query MongoDB databases from within VS Code. +Visual Studio Code has great support for working with [MongoDB](https://www.mongodb.com/what-is-mongodb) databases, whether your own instance or with [Azure DocumentDB (with MongoDB compatibility)](https://learn.microsoft.com/azure/cosmos-db/mongodb/vcore/introduction). With the [DocumentDB for VS Code](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-documentdb) extension, you can create, manage, and query MongoDB databases from within VS Code. ## Install the extension -MongoDB support for VS Code is provided by the [MongoDB for VS Code](https://marketplace.visualstudio.com/items?itemName=mongodb.mongodb-vscode) extension. To install the MongoDB for VS Code extension, open the Extensions view by pressing `kb(workbench.view.extensions)` and search for 'MongoDB' to filter the results. Select the **MongoDB for VS Code** extension. +MongoDB support for VS Code is provided by the [DocumentDB for VS Code](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-documentdb) extension. To install the DocumentDB for VS Code extension, open the Extensions view by pressing `kb(workbench.view.extensions)` and search for 'DocumentDB' to filter the results. Select the **DocumentDB for VS Code** extension. -![Select MongoDB for VS Code](images/mongodb/install-cosmosdb-extension.png) +![Select DocumentDB for VS Code](images/documentdb/install-documentdb-extension.png) ## Connect to MongoDB -Once you've installed the MongoDB for VS Code extension, you'll notice there is a new **MongoDB** Activity Bar view. Select the MongoDB view and you'll see the MongoDB Explorer. +Once you've installed the DocumentDB for VS Code extension, you'll notice there is a new **DocumentDB** logo in the Activity Bar view. Select the DocumentDB logo and you'll see the Explorer. -![MongoDB explorer](images/mongodb/cosmosdb-explorer.png) +![DocumentDB explorer](images/documentdb/documentdb-explorer.png) -To connect to a MongoDB database: +To connect to a MongoDB-compatible database: -1. Select **Add Connection** in the MongoDB view +1. Select **Add New Connection** in the DocumentDB Connection view -1. Next, choose to connect with a connection string or use advanced connection options: +1. Next, choose to connect with a connection string or use Service Discovery options: - * Select **Connect with Connection String**, and then enter the connection string in the connection string Quick Pick. + * Select **Connection String**, and then enter the connection string in the connection string Quick Pick. - The default connection string for a local MongoDB is `mongodb://127.0.0.1:27017`. + ![Database Connection setup](images/documentdb/attach-via-connection-string.png) - ![Database Connection setup](images/mongodb/attach-database-account-connection-string.png) + * Select **Service Discovery**, choose your provider, and then select **Save & Connect**. - * Select **Advanced Connection Settings**, enter the connection details, and then select **Save & Connect**. + ![Database Connection setup](images/documentdb/attach-via-service-discovery.png) - ![Database Connection setup](images/mongodb/attach-database-account.png) +>**Note**: If you're not already signed in to Azure in VS Code, you'll be prompted to do so. This is required to use Service Discovery. ->**Note**: Make sure your MongoDB server (mongod.exe) is running if you are connecting to a local MongoDB server. +Once connected, you can work with the MongoDB server, managing MongoDB Databases, Collections, and Documents. -Once attached, you can work with the MongoDB server, managing MongoDB Databases, Collections, and Documents. +You can expand databases to view their collections in JSON/ Table/ Tree view with their schema and indexes. -![attached MongoDB database](images/mongodb/attached-mongodb-database.png) +![manage mongodb database](images/documentdb/manage-database.png) -You can expand databases to view their collections with their schema and indexes and you can select individual MongoDB Documents to view their JSON. +You can also attach a MongoDB shell to the active connection, simply by right-clicking on the connection itself and selecting **Launch Shell**. -![open mongodb document](images/mongodb/open-document.png) +![MongoDB Connection](images/documentdb/launch-shell.jpeg) -You can also attach a MongoDB shell to the active connection, simply by right-clicking on the connection itself. +>**Note**: Make sure the MongoDB shell (`mongo` or `mongosh`) is [installed](https://docs.mongodb.com/mongodb-shell/install#mdb-shell-install) and is on your path. In the extension's settings, you can choose which shell you are using. -![MongoDB Connection](images/mongodb/connection.png) +## Using Scrapbook ->**Note**: Make sure the MongoDB shell (`mongo` or `mongosh`) [is installed](https://docs.mongodb.com/mongodb-shell/install#mdb-shell-install) and is on your path. In the extension's settings, you can choose which shell you are using. +The **DocumentDB Scrapbook** is one of the most powerful features of this extension. It allows you to write, run, and save MongoDB commands directly within a VS Code editor, helping you prototype queries and scripts -## MongoDB Commands +### Create a New Scrapbook +1. In the DocumentDB Explorer, right-click the desired collection. -There are MongoDB specific commands available in the VS Code **Command Palette** (`kb(workbench.action.showCommands)`) as well as through Explorer context menus. +1. From the menu, click **DocumentDB Scrapbook** and select **New DocumentDB Scrapbook**. -![mongodb commands](images/mongodb/mongodb-commands.png) +![launch documentdb scrapbook](images/documentdb/create-scrapbook.png) -## Using Playgrounds +In a scrapbook, you can reference MongoDB entities and commands and you get rich IntelliSense as you type. Scrapbooks are useful for prototyping database operations and queries. Execute selected lines in the scrapbook queries with **Run Command**. -One of the most powerful features of the VS Code MongoDB integration is **Mongo Playgrounds**. Playgrounds let you create, run, and save MongoDB commands from a VS Code editor. Create a new playground with the **MongoDB: Create MongoDB Playground** command. +![Run scrapbook queries](images/documentdb/run-scrapbook.png) -![new mongo Playground](images/mongodb/new-mongo-scrapbook.png) +## MongoDB on Azure DocumentDB -In a playground, you can reference MongoDB entities and commands and you get rich IntelliSense as you type. Playgrounds are useful for prototyping database operations and queries. Execute selected lines in the playground queries with the **MongoDB: Run Selected Lines From Playground** command. - -![mongodb Playground](images/mongodb/scrapbook.png) - -![Run Playground queries](images/mongodb/run-playground.png) - -## MongoDB on Azure - -You can easily create a MongoDB cluster on Azure for **Free** with [MongoDB Atlas](https://www.mongodb.com/cloud/atlas/signup?utm_campaign=marketplace&utm_source=signup&utm_medium=marketplace). - -Choose **Create a New Cluster** from the dashboard and choose **Azure** as the Cloud Provider. Once the cluster is created, connect to using the connection string provided by **MongoDB Atlas**. - -![Create Azure Cluster](images/mongodb/create-azure-cluster.png) +You can easily create a managed MongoDB cluster on Azure for **Free** with [Azure DocumentDB](https://aka.ms/documentdb). ## Next steps +* [Index Advisor](https://learn.microsoft.com/azure/documentdb/index-advisor) - Learn how to optimize your MongoDB performance with Index Advisor. * [Azure Extensions](/docs/azure/extensions.md) - The Visual Studio Marketplace has hundreds of VS Code extensions for Azure and the cloud. * [Deploying to Azure](/docs/azure/deployment.md) - Learn step-by-step how to deploy your application to Azure. * [Working with Docker](/docs/azure/docker.md) - Put your application in a Docker container for easy reuse and deployment.