Today we introduce the first beta of the new MongoDB Shell (
mongosh), a shell for MongoDB with a modern user experience that will grow in functionality along with the MongoDB data platform.
Since the beginning, MongoDB has had a shell (
mongo) and almost everybody who’s ever used MongoDB has used it for one reason or another. From running simple queries to scripting admin operations, our users use the shell almost every day, several times a day.
The more MongoDB grows as a data platform and it expands with new functionality and new products, the more the shell needs to do. We have considered how to extend mongo to grow along with the MongoDB platform, but we’ve come to realize that this would not have been the right approach.
For this reason, we went back to the drawing board and designed a new MongoDB Shell from the ground up. The new MongoDB Shell is built to be extensible, so we can easily add new functionality as new products and services are added to the MongoDB platform, it’s embeddable, so in addition to using it in your terminal, you can use it (or parts of it) inside other products (one example of this is MongoDB for VS Code), and last but not least it provides a modern command-line experience with enhanced usability features.
The MongoDB Shell is a standalone product, it’s developed separately from the MongoDB Server and it’s open-source under the Apache 2 license.
You can download the MongoDB Shell from the MongoDB Download Center. Select the platform you need (Windows, Linux, macOS), download the zip file, extract the
mongosh (mongo - es - eɪtʃ) binary to your preferred location, make it executable, and run it.
On macOS, the best way to install the MongoDB Shell is via Homebrew:
$ brew tap mongodb/brew
$ brew install mongosh
For detailed installation instructions, check the documentation.
Good user experience is key in any type of software, including the tools we use in the terminal. With this in mind, when we designed the new MongoDB Shell we kept user experience and ease of use in good consideration. We took inspiration from what the MongoDB community has been building on top of the mongo shell over the years and from other interactive experiences on the command line that are available in the open-source world.
We focused primarily on 4 things:
- Syntax highlighting: to make things more readable and to makes it easier to spot errors;
- Intelligent autocomplete: to save time when typing and to assist you when you don’t remember a command or an operator;
- Contextual help: when autocomplete is not enough, you can get contextual help for shell classes and commands with direct links to the online documentation;
- Error messages: when something goes wrong, the MongoDB Shell will tell you what happened and help you address the problem.
As you’d expect, in the MongoDB shell you can run scripts. In fact, the MongoDB shell is a very powerful scripting environment. Because it’s built on top of the Node.js REPL, the whole Node.js API and ecosystem of npm packages are available to you.
For example, I can write a script that fetches a web page, parses it, extracts some data, seeds a collection with it, and displays the results.
Try it now!
The MongoDB Shell is being actively developed and during this Beta period, we look forward to your feedback to help shape the direction of the product. Download it and try it today and let us know what you think:
- Install the MongoDB Shell from the MongoDB download center
- Get a free MongoDB Atlas cluster if you don’t have a MongoDB server already
- Connect to it and start writing commands
You can find more information about the MongoDB Shell and all its features in the documentation.