Documentation

Saved Queries Library

Saved Queries

Quick Start

Access the Query Library to manage your saved queries:

  1. Open the Query Library from the sidebar or main menu
  2. Browse your queries organized by connection, database, and collection
  3. Use the search bar to find specific queries by name or collection
  4. Double-click any query to run it immediately
  5. Use folders to organize queries within collections
Query Library showing the hierarchical folder tree with connections, databases, collections, and saved queries

Understanding the Organization

The Query Library automatically organizes your saved queries in a hierarchical structure for easy navigation:

  • Connections - Top-level organization by database connection. Each connection can be expanded to show its databases.
  • Databases - Within each connection, databases group queries by the database they target. Expand to see collections.
  • Collections - Collections contain the actual saved queries. You can further organize queries using custom folders.
  • Custom Folders - Create your own folder structure within collections to organize queries by purpose, project, or any scheme you prefer.

Viewing Your Saved Queries

The Query Library provides multiple ways to view and navigate your queries:

Folder Tree Navigation

  • Expand/Collapse Nodes - Click on any connection, database, collection, or folder to expand or collapse its contents. The library remembers your expanded state between sessions.
  • Visual Indicators - Each level uses distinct icons and colors: green for connections, blue for databases, cyan for collections, and yellow for folders.
  • Item Counts - Each node shows the number of items it contains in parentheses, helping you quickly see where your queries are located.

Query Display

Each query in the list shows:

  • Query Name - The descriptive name you gave when saving
  • Query Type Badge - Visual indicator showing whether it's a Query (blue), Aggregation (purple), or SQL query (green)
  • Collection Name - Quick reference to which collection the query targets
  • Last Modified - Relative time (e.g., "2h ago", "3d ago") showing when the query was last updated
Individual query items showing name, type badge, collection, and modification time

Finding Queries

Search Functionality

The search bar at the top helps you quickly locate queries:

  • Name Search - Type any part of the query name
  • Collection Search - Find queries by collection name
  • Database Search - Locate queries by database name
  • Connection Search - Filter by connection name
  • Folder Search - Find queries in specific folders
  • Real-time Results - The tree updates as you type, showing only matching queries and their parent folders

Sorting Options

Two sorting modes help you organize your view:

Sort Mode Description Best For
Name Alphabetical order by query name Finding specific queries when you know the name
Date Most recently modified queries first Quickly accessing queries you've been working with

Running Saved Queries

Several ways to execute your saved queries:

  • Double-Click - Double-click any query in the list to immediately open it in a new activity tab and execute it.
  • Play Button - Hover over a query to reveal action buttons, then click the play icon to run the query.
  • Keyboard Navigation - Use arrow keys to navigate the list, then press Enter to run the selected query.
  • Context Menu - Right-click a query to access a menu with Run Query as the first option.

Note: Running a query opens it in the appropriate activity type (Collection, Aggregation, or SQL Query) based on how it was saved.

Managing Query Details

Renaming Queries

Change the name of a saved query:

  1. Hover over the query to reveal action buttons
  2. Click the pencil/edit icon
  3. Enter the new name in the dialog
  4. Click Save to update

You can also right-click a query and select "Rename" from the context menu.

Duplicating Queries

Create a copy of an existing query:

  1. Hover over the query you want to copy
  2. Click the copy icon in the action buttons
  3. A duplicate is created with "(Copy)" appended to the name
  4. Rename the copy as needed

This is useful for creating variations of similar queries without starting from scratch.

Query hover state showing action buttons for run, rename, clone, and delete

Deleting Queries

Remove queries you no longer need:

Delete Single Query

  1. Locate the query you want to remove
  2. Hover over it to reveal action buttons
  3. Click the trash icon (red when hovered)
  4. Confirm the deletion in the dialog

Alternatively, right-click the query and select "Delete" from the context menu.

Warning: Deleting a query is permanent and cannot be undone. Make sure you have exported important queries as a backup.

Organizing with Folders

Create custom folders to organize queries within collections:

Creating Folders

  1. Navigate to a collection or existing folder
  2. Hover over it to reveal the folder-plus button
  3. Click to open the Create Folder dialog
  4. Enter a descriptive folder name
  5. Click Create

You can also right-click a collection or folder and select "Create Folder" or "Create Subfolder" from the menu.

Moving Queries Between Folders

Reorganize your queries using drag and drop:

  1. Click and hold on a query
  2. Drag it to a collection or folder
  3. Release to drop it in the new location

Queries can only be moved within the same connection, database, and collection.

Renaming Folders

  1. Right-click on a folder
  2. Select "Rename Folder" from the menu
  3. Enter the new name
  4. All queries in the folder are updated automatically

Deleting Folders

  1. Right-click on a folder
  2. Select "Delete Folder"
  3. Confirm the deletion

Warning: Deleting a folder also deletes all queries inside it. This action cannot be undone.

Folder context menu showing options to create subfolder, rename, and delete

Import and Export

Exporting All Queries

Create a backup or share your entire query library:

  1. Click the download button in the toolbar (top-right of the window)
  2. A JSON file downloads containing all your saved queries
  3. The file includes metadata like creation dates and folder organization
  4. Share this file with team members or store it as a backup

Importing Queries

Load queries from a file:

  1. Click the upload button in the toolbar
  2. Select a JSON file exported from Query Library
  3. The system validates the file format
  4. All queries from the file are added to your library
  5. Duplicate queries are created with new IDs

Tip: Importing does not replace existing queries. If you import a file containing queries you already have, you'll end up with duplicates.

Keyboard Shortcuts

Navigate the Query Library efficiently with keyboard shortcuts:

Shortcut Action
Arrow Down Move selection down to next item
Arrow Up Move selection up to previous item
Arrow Right Expand selected folder
Arrow Left Collapse selected folder or jump to parent
Enter Run selected query or toggle folder expansion
Page Down Jump down 10 items
Page Up Jump up 10 items

Note: On macOS, keyboard shortcuts work the same way using the arrow keys and standard navigation keys.

Context Menus

Query Context Menu

Right-click on any query to access these options:

  • Run Query - Execute the query in a new activity tab
  • Rename - Change the query name
  • Clone - Create a duplicate copy
  • Delete - Remove the query (with confirmation)

Collection Context Menu

Right-click on a collection to access:

  • Create Folder - Add a new folder within the collection

Folder Context Menu

Right-click on a folder to access:

  • Create Subfolder - Add a nested folder
  • Rename Folder - Change the folder name
  • Delete Folder - Remove the folder and all its contents

Pro Tips

  • Persistent folder state - Keep your folder tree expanded the way you like it - the Query Library remembers your expansion state between sessions, so you don't have to keep expanding the same folders.
  • Organize by purpose - Use folders to organize queries by purpose (e.g., "Reports", "Admin Tasks", "Testing") rather than by technical details. This makes it easier to find queries when you need them.
  • Export for backups - Regularly export your query library as a backup. If you work with critical queries, keep these exports in version control or a backup system.
  • Smart sorting - The "Sort by Date" option is great for finding queries you've been working on recently, while "Sort by Name" is better when you know exactly what you're looking for.
  • Keyboard navigation - You can use keyboard navigation to quickly browse through queries. Press Enter on a selected query to run it immediately without reaching for the mouse.
  • Clone before deleting - Before deleting old queries, consider cloning them first if there's any chance you might need them later. Storage is cheap, but recreating a complex query from memory is not.
  • Collection Activity - Where you create and save find queries that appear in the Query Library
  • Aggregation Activity - Create aggregation pipelines that can be saved and managed in the Query Library
  • SQL Query Activity - Write SQL queries against MongoDB that can be saved to the library
  • Save Query Dialog - The interface for saving new queries with names, descriptions, folders, and tags
  • Load Query Dialog - An alternative way to browse and load queries from within other activities

Ready to try VisuaLeaf?

Download and start managing your MongoDB databases with ease.

Download Free Trial