Reuse queries: history and saved queries

Find any query you ran in the Query History, save queries by name, organise them in folders with the Query Manager, and load them again.

Every query you run is kept in the Query History. Queries you want to keep under a name go to the Query Manager, in folders. Both work for collection queries, aggregation pipelines, SQL statements and IntelliShell scripts.

The Query History window listing the last queries run on acme_store

Find a query you ran

  1. In a Collection Tab, click Query history in the query toolbar (or press the Down arrow in the Query field to search the history for what you typed).
  2. Entries are listed newest first, with their target (connection, database, collection) and when they ran. Type in the search box (Search the history (Ctrl+F)) to filter by query text, database or collection.
  3. Select an entry to preview it, then press Enter or double-click (Select): it loads into its tab (or a new Collection Tab on its collection) and runs.

Running the same query on the same collection again moves its entry to the top instead of adding a copy. Opening a collection and paging are not recorded.

CommandShortcutWhat it does
SelectEnterLoads the entry and runs it
Remove SelectedDeleteRemoves the selected entries
Clear AllShift+DeleteRemoves every entry, after confirmation (cannot be undone)
Save as querySaves the entry in the Query Manager
Set As Default QueryMakes it the collection’s default query
SearchCtrl+FFilters the list

The history holds 1,000 entries by default; set Maximum query history size: (1 to 100,000) in Edit > Preferences (Ctrl+P), General page. The oldest entries go first. A query over 1 MiB runs but is not recorded.

The Aggregation Editor, SQL Query and IntelliShell (Script History and Browser) have their own history lists, opened from their toolbars.

Save a query

  1. Write the query in the query bar.
  2. Click Save query or press Ctrl+S.
  3. Type the Query name: and choose a folder.
  4. Tick Save target details (connection, database and collection) to remember where it runs.
  5. Click Save. The status bar says Query “…” saved.

A name already used in the same folder is refused (Name is already in use: overwrite that query, or choose another name), unless you choose Overwrite.

The query bar’s fields and the Find Query Options are saved, including date tags as typed.

Load a saved query

  • In a Collection Tab, click Load query (Ctrl+O): the menu lists saved queries; pick one to load and run it in this tab. Open Query Manager opens the full list.
  • In the Query Manager, select a query and click Load (Enter). A collection query runs in a Collection Tab on its saved target, or on the collection you choose. A SQL query opens in a new SQL Query tab, an aggregation in the Aggregation Editor, and an IntelliShell script in a new IntelliShell tab (not run) on the server, database or collection you pick.

Organise queries in the Query Manager

CommandShortcutWhat it does
New queryCreates a query by hand: name, location, Query type: (Collection query, IntelliShell script, SQL Query, Aggregation query), target, text
New folderCreates a folder (folders can be nested)
Quick edit / Edit queryCtrl+EChanges name, folder, fields and target
RenameF2Renames the query
DuplicateCopies it as name (1), name (2)…
DeleteDeleteDeletes it, after confirmation
Show info paneShows the selected query’s preview
Remove query targetForgets its connection, database and collection
Show Queries from:Shows one folder, or Show All folders
SearchCtrl+FSearch saved queries by name and text

Drag a query onto a folder to move it.

With Team Sharing, saved queries can also live in shared folders; that is covered with team features.

Troubleshooting

  • A saved collection query does not run where I expect: it runs on its saved target. Edit the query (Ctrl+E) to change the target, or Remove query target to choose each time.
  • “The history entry is gone”: it was removed or dropped as the history reached its maximum size.
  • A query is missing from the history: queries over 1 MiB are not recorded, and only queries you ran (not pages you browsed) are.