VS Code extension, available in your IDE with Mongo.
Visual Studio Code has become the developer’s favorite editor. MongoDB has introduced a new extension to VS Code that makes it super easy to use with Mongo.
What’s in the bag?
VS Code is working hard to increase developer productivity. Meanwhile, MongoDB has built an extension called MongoDB for VS Code that allows you to connect directly to the MongoDB Shell and MongoDB Atlas from the editor. Now you can connect to Mongo Shell or perform basic Mongo operations using GUI tools (such as MongoDB Compass, Robomongo, etc.) without having to navigate to a terminal.
With extensions, you can:
- Connect directly from the editor to the MongoDB Shell or Atlas Cluster.
- Browse databases, collections, and documents.
- Review and analyze your architecture.
- Use autocomplete and syntax to highlight prototype CRUD actions and MongoDB commands in MongoDB Playground.
Install the extension
To install extensions, simply search in VS Code’s Extension search, or navigate to MongoDB for VS Code in the marketplace.
Connect to the mongo
This extension allows you to connect to multiple MongoDB instances. You can connect to a local MongoDB instance, an Atlas cluster, or any self-managed instance.
To connect, you can either enter a host name and port, or provide a connection string like this:
mongodb://localhost:27017/
Copy the code
Once connected, the extension will give you a tree view of databases, collections, and documents. In addition, you can have an overview of the architecture of each collection.
When writing aggregations and queries, we may need to look at the collection pattern repeatedly. It is very helpful to have schemas in front of you when querying databases.
MongoDB Playground in the editor
Writing Mongo queries can be daunting in a terminal, where there is no auto-completion and syntax highlighting for queries. MongoDB Playground allows you to have features like query auto-completion and syntax highlighting directly within VS Code. These features make it easy to write, understand, execute, and view the results of MongoDB queries. It’s also a great tool for putting test data into a database and sharing it with your teammates.
To Create Playground, click the three horizontal points above Connect, and then select Create MongoDB Playground.
When you execute queries written on Playground, the extension displays the results in the output of the VS code, and Playground opens as a file in the editor, so you can save the file for reference. Having this playground also allows you to prototype queries while writing other application code.
The end of the
MongoDB just launched this extension for VS Code. It’s not as featureas MongoDB Compass or other tools, but its current capabilities have made it easier for me to use Mongo. It has to evolve, so we can expect MongoDB to have a lot of new features soon.
Source: medium.com/better-prog… , written by Haseeb Anwar, translated by Public account: Front-end Full Stack Developer