Q: When I query MongoDB, I find it hard to read and compare the results between documents, especially when there are embedded documents. Can Studio 3T help?
Welcome to the first Studio 3T Ask Manatees Anything – #Studio3T_AMA. Want to know how to use Studio 3T to make your MongoDB life better? Just tweet and use #Studio3T_AMA or email [email protected].
A: As you know, MongoDB is built around JSON and JSON is designed to be human readable. As you found, as soon as there’s any depth in a JSON document though it becomes quite hard to parse the relationships between different fields. And that’s doubly so when you want to compare deeply embedded values.
The Studio 3T Table view displays the fields as columns in the table and behaves more like a spreadsheet than just a table. That means you can tab into it, or click directly on a field, and navigate with the keyboard.
Where there are embedded fields or arrays, the number of embedded objects within is shown. Clicking into any one of those embedded fields to view their contents, displays just the id and contents for all the records. So if we clicked on a field in the airport column the view would change to:
You can also do that by navigating to the embedded field you want to see and pressing enter to descend into the contents of that embedded field. To return to the previous level, just tap backspace and you ascend back to the previous view. You could say the Table view is a spreadsheet with hidden depths.
If you are comparing documents, you’ll likely want to view those embedded fields alongside the other data in each document. For that you can pick your cell and select Show Embedded Fields from the context menu, or tap command-enter and the fields will be virtually promoted up to the current level:
Notice how both fields within the “Airport” embedded field are now immediately visible. Want to see all embedded fields? Show All Embedded Fields is there on the context menu too. There’s no shortcut key for that yet. There’s also Hide All Embedded Fields for when you want to fold the table back to its most minimalist form.
When you do show the embedded fields, you will notice that you can still see the field that contains the embedded field. If that is a bit visually noisy for you, the Show/Hide Column function (Control/Command-T) can toggle a column in and out of the view. You’ll find it on the context menu under Column along with Make All Columns Visible to undo all your toggling.
Your expansion selections are sticky so you can come back to a collection and still see it expanded the way you left it. Over in Preferences, there’s an option to set the default to show (or hide) all the embedded fields by default when you first open a Table view up.
And yes, you can still flip to the Tree and JSON views if you want and return to the Table view. Tree and JSON views can also be navigated around with the keyboard. You can navigate the Tree with the keyboard too, and the JSON view is a traditional read-only text view you can cursor around.
You’ll find these views and options throughout Studio 3T and getting a good handle on them is the key to navigating MongoDB data smoothly.