I thought this was worth sharing. A former colleague of mine from Red Gate put me in touch with an awesome company called 3T Software Labs, who have a suite of tools for working with MongoDB, including a great shell for MongoDB called MongoChef. I was fortunate enough to be able to spend some time this afternoon running through a usability test on MongoChef with one of 3T’s co-founders, Thomas Zahn.
MongoChef seems to offer the best of both whilst also being more capable and is being rapidly developed on a very short release cycle so the improvements seem to be coming thick and fast, so I suspect it’ll replace them both from now on.
Anyway, I really just wanted to run through some of the functionality very quickly…
First off, download and install MongoChef. If you want to use the integrated shell, make sure you’ve also got the MongoDB binaries installed.
Connecting to a MongoDB instance is dead simple. Just click the big green Connect button on the welcome screen, or use the corresponding toolbar button:
This opens up the Connection Manager:
Now click New Connection, and give your connection a name. The really nice thing is that it’s easy to populate this dialog from a URI, for example, one that you use in your web.config, using the From URL button:
Just paste in your URI, click OK, and you’re good to go:
Likewise, if you need a URI as a connection string, you can grab that using the To URI button:
Just double-click on any connection in the Connection Manager to connect to that instance.
Active connections are shown in the treeview on the left of the main window. You can drill in to view databases and connections:
You can double-click on a collection to open it. Pagination is customisable and you can drill into documents:
There are also three different views for documents: Tree View, Table View, and JSON View.
My favourites are definitely Tree View and JSON View. Table View works particularly well for very flat documents.
To use the Query Builder just hit the corresponding button in the top-right of the collection view:
To build your query, just:
- drag the fields you want to query against into the Query section, and set the query criteria for each field
- drag the fields you’d like to sort by into the Sort section,
- the fields you’d like returned into the Projection* section.
*A projection defines the subset or shape of data you’d like to receive back from MongoDB. It’s analagous to the column list after SELECT in a SQL query.
Then, to run your query, just click the Run button. Here’s an example:
Editing documents is just as easy as querying. Just double-click on the value you want to edit and type in something else. This even works with projections:
Enter your query in the pane at the bottom of Shell, which includes intellisense/autocomplete to help you, which is absolutely invaluable. If it takes to long to appear just use the standard CTRL+SPACE shortcut to force it:
You can hit ENTER to execute your query. Results appear in the pane at the top of the Shell.
If this isn’t the behaviour you want just uncheck Enter Executes.
If you’ve ever installed MongoDB from scratch you’ll know that setting up users can be a royal pain in the backside. Fortunately MongoChef provides help with user management too.
Just select the database you want and click Users on the toolbar:
You can drill into each user to see which roles they have. Click Add to add a new user:
Assign a username and password to your new user. If you want them to be able to do anything, you’ll also need to assign one or more roles to them. Click Grant Roles to do this:
To assign a single role, just double-click on it. To assign multiple roles, use CTRL+Click to multi-select, then click Grant:
Back in the Add User dialog box just click the Add User button, and you’re done.
This is by no means a comprehensive look at all the features available in MongoChef, but hopefully it’s given you a flavour of what the tool can do. I’d strongly recommend you try it yourself though, so here’s that download link again.
MongoChef is available for Windows, OSX, and Linux, and is compatible with all recent 2.x versions of MongoDB, along with the latest 3.0 release. It’s free for personal, non-commercial use, and a snip at US$69 + VAT for a commercial license.