Q: I just cleared the query I’ve been building and I don’t know how to get it back? Is there any way to find a previous query? HELP!
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: Don’t panic! Studio 3T has you covered. Every time you execute a query in the Collections Tab it is automatically saved in the Studio 3T query history. So the first thing to reach for is your Query History which you can get to by clicking on the “Search Query History” icon:
Click here and that will bring up the “Find Query Manager”, where we can find your missing query.
Searching with the Find Query Manager
Now, this is a store of all your query history from across all your collections.
It’s not per collection, so you can recall a query from the history to run against any collection. Each entry in the history includes the query itself, the associated projection and sort settings and the values for skip and limit.
You will also see the date and time for when that query was executed. So, if you wanted to find that query you made on Tuesday at 15:00, just scroll down the list and you’ll find the queries you were making at that time.
If you want to locate your query by say, a field name or value that you know you used, then the Search History field is the tool for you. Click on the Search History field or press Control/Command+F to focus on it and enter your search term.
Selecting a row in the history will display all its details in the Overview in a more readable format.
The list will update as you type showing only matches to that term for either field names or values.
Rescuing from the Find Query Manager
Once you find the query you are interested in, the Find Query Manager has a couple of options for what you can do with it. You can click the Select button (or double click the row in the list) and the query will be immediately loaded into your Collections Tab.
Or you can bookmark your query for future use by selecting “Save As Bookmark” at the top of the Find Query Manager. Studio 3T will ask for a bookmark name. It will then be added to the Studio 3T query bookmarks. You will be able to recall them through the star icon to the right of the Query Manager icon. Or if you have the Find Query Manager open, just click the Bookmarks tab.
Finally, you can make your query a default query for the collection when displayed in the Collections tab. A default query is a sticky query that is automatically loaded whenever the collection is opened in the collections view. You can set a different default query for each and every collection. To use your selected query, click the “Set As Default Query” button at the bottom of the Find Query Manager. You manage the default query for a collection through the anchor icon to the left of the Query Manager icon.
We have some questions about the bookmark and default query controls in the Ask Manatees Anything inbox, so we’ll talk about them in the near future. Suffice to say you can send your queries to either.
Tidying Up
Finally there are two other items on the Find Query Manager worth noting. Remove Selected will delete one selected row from your history, while Clear All will remove all of them. Both prompt for confirmation that you want to delete; once it is gone, it’s gone for good.
All being well, if you’ve got this far, you’ve already recovered that query you lost and you’re back digging deep into MongoDB and your data with the help of Studio 3T.