Q: Studio 3T has bookmarks but what do you actually save in a bookmark?
Welcome to the latest 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: Yes, just like a web browser can bookmark a web page’s URL for you to return to later, Studio 3T bookmarks can remember queries or aggregations for you.
We previously looked at Query History and saw that it recorded each query expression, fields for projection and sort directives. Those three things make up a recordable query. The query history records them on an on-going basis. If there’s a query you want to keep and reuse, that’s where the Studio 3T bookmarks come in.
To save any query as a bookmark, you need to click on the Bookmark icon, the star in the top right of the Query window.
If the Bookmark icon is white, the current query does not appear in the bookmarks. If the icon is gold, the query already has a bookmark. Clicking on the Bookmark icon prompts you for a name for your bookmark which can be any text you wish.
Click ok and you have created a bookmark.
Once you’ve bookmarked a query, you can retrieve it from the bookmark menu, which appears when you click the downward point triangle to the right of the bookmark icon:
Managing Bookmarks
The named bookmarks turn up in the list after the Bookmark Manager. If you select the Bookmark Manager, you’ll see it looks very much like the Query History dialog and that’s because it is a tab in the same window as the Query History. It’s the Find Query Manager which unites bookmarks and query history:
Here you can see the query we just bookmarked, when we bookmarked it and, below that, the query itself. From here you can edit the bookmark where you can rename the bookmark or manually adjust the query parameters.
If you have a lot of changes to make, it’s probably easier to go to the bookmark, edit the query with the Visual Query Builder (and verify it). Then you can just bookmark again.
The edit dialog shows exactly what Studio 3T stores with a bookmark. What is worth noticing is what isn’t stored with a query.
The Magic Of Bookmarks
There is something deliberately missing from the bookmark, the name of the collection (and database connection) of the original query. This means we can apply the a bookmark to any collection. Of course, the collection needs to have the same field names to work but you can still apply a bookmark and then edit the query to match the new collection’s schema.
By not storing the collection and database name, bookmarks are able to be a cross database template for your queries. You can create a library of your base queries and apply them before you start tuning them for particular results – for example, you may regularly want to project only a particular set of fields and sort them. You’ll notice that projection and sort settings are part of the bookmark and you can bookmark an empty query with those settings.
Queries, Scripts, SQL and Aggregation
The Query bar is just one of the places you can find the Bookmarks icon. You can also find it in the Aggregation Editor where it you can used ir to bookmark the whole aggregation pipeline for later reuse. Unlike query bookmarks, this does save the collection name in the bookmark. When you use it on a different collection, Studio3T automatically swaps in the name of the current collection. There are also bookmarks in Intellishell, where you can bookmark the entire script, and in SQL query where you can bookmark the text of the SQL query. Each one of these bookmark managers is a separate set of bookmarks, designed to be appropriate to the tool you are using.