Documentation

MongoDB Query Builder

Mongo Query

The Collection Activity is your primary workspace for exploring, querying, and managing MongoDB collection data. It provides powerful querying capabilities with both visual and code-based interfaces, multiple view modes for data visualization, inline editing, batch operations, and seamless integration with other VisualLeaf tools.

Quick Start

Start querying your collection in seconds:

  1. Select a collection from the sidebar tree to open it
  2. Enter a MongoDB query in the Query field (e.g., { status: "active" })
  3. Press Enter or click Run to execute the query
  4. Browse results in Tree View, Table View, or BSON View
  5. Use the Query Builder toggle for visual query construction
Collection Activity interface showing query field, view mode tabs, and results area
Video COLL02 Collection Query Demo - Watch this demonstration of VisualLeaf's query builder and result view system capabilities. This video showcases key features including tree view, table view, BSON view, inline search, visual query builder, drag-and-drop functionality, and AI-powered query generation.

View Modes

Collection Activity offers four specialized view modes, each optimized for different use cases:

View mode selector showing Tree View, Table View, BSON View, and Explain View tabs

Tree View

Hierarchical display ideal for exploring nested document structures.

  • Expand/collapse nested objects and arrays
  • Color-coded data types with icons
  • Inline editing of field values
  • Search within fields and values
  • Three search modes: Field, Value, or Both
  • Navigate search results with next/previous

Best for: Exploring complex nested documents, understanding document structure, debugging data

Table View

Spreadsheet-like display for analyzing multiple documents side by side.

  • Sortable columns with ascending/descending order
  • Resizable columns for custom layouts
  • Show/hide columns dynamically
  • Drag and drop to reorder columns
  • Multi-row selection for batch operations
  • Search across all visible columns
  • Handles nested fields as expandable columns

Best for: Comparing documents, bulk analysis, spreadsheet-style data review

BSON View

Raw MongoDB Extended JSON display for precise data inspection.

  • Syntax-highlighted JSON with proper formatting
  • Shows exact BSON types (ObjectId, Date, Binary, etc.)
  • Copy entire EJSON representation
  • Preserves type information for export

Best for: Verifying exact data types, debugging type issues, preparing for export/import

Explain View

Query performance analysis and optimization insights.

  • Query execution plan visualization
  • Index usage analysis
  • Execution statistics (docs examined, returned, time)
  • Performance recommendations
  • Index suggestions for slow queries

Best for: Performance tuning, index optimization, understanding query behavior

Video COLL04 Switching Between View Modes - Watch how to navigate between Tree View, Table View, BSON View, and Explain View. See how each view mode presents the same data differently, learn when to use each view, and understand how to leverage view-specific features like tree expansion, column sorting, BSON type inspection, and query performance analysis.

Query Interface

Build and execute MongoDB queries using intuitive input fields with syntax highlighting and auto-completion.

Query interface showing Query field, Options toggle, Run button, and Query Builder toggle

Query Fields

Field Description Example
Query MongoDB filter criteria (find query) { status: "active", age: { $gte: 18 } }
Projection Fields to include (1) or exclude (0) { name: 1, email: 1, _id: 0 }
Sort Sort order: 1 for ascending, -1 for descending { createdAt: -1, name: 1 }
Limit Maximum number of documents to return 50, 100, 200, 300, 500
Skip Number of documents to skip (for pagination) 0, 50, 100
Advanced options expanded showing Projection, Sort, Limit, and Skip fields

Query Execution Options

  • Run / Run Find One: Execute the query and return multiple documents based on limit setting, or return only the first matching document.
  • Run Count: Count the total number of documents matching the query without fetching them.
  • Cancel Query: Stop a running query immediately. Shows elapsed time during execution.

Query Features

  • Syntax Highlighting: ACE editor with JSON mode for readable queries
  • Auto-completion: Press Ctrl+Space (or Cmd+Space on Mac) to trigger field name suggestions
  • Field Suggestions: Auto-complete fields from your collection schema as you type
  • Expand Editor: Click the expand icon on any field to open a full-screen JSON editor
  • Validation: Real-time JSON syntax validation with error indicators
  • Query Timer: Live execution time display (turns amber after 2s, red after 5s)
  • Single-Line Input: Press Enter to run query (newlines are automatically converted to spaces)

Visual Query Builder

Build complex MongoDB queries visually without writing JSON syntax. Toggle the Query Builder panel to show or hide it.

Query Builder panel showing field selector, operator selection, and condition builder

Query Builder Features

  • Drag and Drop Fields: Select fields from your collection schema and drag them into the query
  • Visual Operator Selection: Choose from dropdown menus of MongoDB query operators ($eq, $gt, $lt, $in, $regex, etc.)
  • AND/OR Logic Builder: Combine multiple conditions with visual AND/OR grouping
  • Type-Aware Inputs: Field inputs adapt based on data type (dates, numbers, strings, booleans)
  • Projection Builder: Visually select which fields to include or exclude from results
  • Sort Builder: Add sort criteria with simple ascending/descending toggles
  • Real-time JSON Preview: See the generated MongoDB query update as you build
  • Bi-directional Sync: Changes in the Query Builder update the Query field and vice versa
  • Reset Button: Clear all conditions and start fresh
  • Resizable Panel: Drag the panel edge to resize (width is preserved per activity)
Video COLL08 Using the Visual Query Builder - Learn how to build MongoDB queries using drag-and-drop. Start by toggling the Query Builder panel, drag fields from the schema tree into the query area, select operators from dropdowns ($eq, $gt, $in, $regex), combine conditions with AND/OR logic, add projection and sort criteria, and watch the JSON query generate in real-time as you build visually.

AI Query Builder

VisualLeaf AI allows you to describe what you want in plain English and automatically generates the corresponding MongoDB query.

AI Features

  • Natural Language Queries: Type "Find all users older than 30" and get the MongoDB query automatically
  • Conversation Context: AI remembers your previous requests for follow-up refinements
  • Schema-Aware: AI understands your collection structure for accurate field suggestions
  • Query Explanation: Each generated query includes an explanation of what it does
  • Multiple AI Providers: Support for OpenAI, Anthropic, and other LLM providers

Setup: To use the AI Query Builder, configure your AI provider in VisualLeaf Configuration. Go to Settings → AI Configuration and add your API key.

Document Editing

Edit documents directly in the Collection Activity using multiple editing modes.

Tree View with inline editing of a field value

Inline Editing (Tree View)

Edit field values directly in the tree view without opening dialogs.

  • Click any value to edit in place
  • Type-appropriate editors (text, number, date, boolean)
  • Press Enter to save, Esc to cancel
  • Changes are saved to MongoDB immediately
  • Undo/Redo support with Ctrl+Z / Ctrl+Shift+Z

Dialog Editing

Edit entire documents in a full-screen JSON editor.

  • Right-click document → Edit Document
  • Full ACE editor with syntax highlighting
  • Validation before saving
  • Cancel to discard changes
  • Perfect for complex nested structures

Batch Editing

Apply the same changes to multiple documents at once.

  • Select multiple rows in Table View
  • Right-click → Batch Update
  • Define update operations ($set, $unset, $inc, $push, $pull)
  • Preview affected documents before applying
  • Confirmation dialog with update count
Edit Document dialog with JSON editor
Video COLL11 Document Editing Workflow - See both editing methods in action. First, watch inline editing in Tree View: click a field value, modify it directly, press Enter to save or Esc to cancel. Then see dialog editing: right-click a document, select Edit Document, modify the entire JSON structure in the full-screen editor with syntax highlighting and validation, and save changes back to MongoDB.

Field Operations

Manage document fields with powerful operations available from the context menu.

  • Add Field: Add a new field to a document or nested object. Right-click on a document or object → Add Field. Specify field name, data type, and initial value.
  • Rename Field: Change a field's name while preserving its value. Right-click on a field → Rename Field. Uses MongoDB's $rename operator.
  • Delete Field: Remove a field from a document. Right-click on a field → Delete Field. Uses MongoDB's $unset operator. Requires confirmation.
  • Edit Field Value: Modify field values with type-appropriate editors. Click to edit inline, or right-click → Edit Value for a dialog editor with validation.

Copy Operations

Copy data in multiple formats for use in other tools or documentation.

Context menu showing copy options
Copy Option Description Use Case
Copy Document Copy entire document as JSON Paste into code, documentation, or MongoDB shell
Copy Value Copy a field's value only Extract specific data like IDs, names, or numbers
Copy as EJSON Copy with Extended JSON type preservation Preserve ObjectId, Date, Binary types for import
Copy Field Name Copy the field's name/key Use in queries, projections, or code
Copy Field Path Copy dot-notation path to nested field Query nested fields (e.g., user.address.city)

Batch Operations

Perform actions on multiple documents simultaneously for efficient data management.

Table View with multiple rows selected and batch operation menu

Batch Update

  • Select multiple documents in Table View (click checkboxes or use Shift+Click)
  • Right-click selection → Batch Update
  • Define update operations using MongoDB update operators: $set, $unset, $inc, $push, $pull
  • Preview shows document count and example changes
  • Confirmation required before applying

Batch Delete

  • Select multiple documents in any view
  • Right-click selection → Delete Documents
  • Confirmation dialog shows count of documents to be deleted
  • Permanent action - deleted documents cannot be recovered

Caution: Batch operations affect multiple documents at once. Always review the selection count and preview before confirming. Consider testing on a non-production database first.

Video COLL14 Batch Operations - Learn how to perform bulk updates and deletions. Switch to Table View, select multiple documents using checkboxes or Shift+Click, right-click the selection to open the context menu. For Batch Update: choose update operators ($set, $inc, $push), define the changes, preview affected documents, and confirm. For Batch Delete: review the selection count and confirm deletion of multiple documents at once.

Import & Export from View

Quickly import or export data directly from the Collection Activity toolbar.

  • Import Data: Access from Open In → Import Data. Opens Import Activity pre-configured for the current collection. Supports JSON, CSV, and BSON formats.
  • Export Data: Access from Open In → Export Data. Opens Export Activity with your current query pre-filled. Export results to JSON, CSV, BSON, or SQL formats.

Search Within Results

Search within query results without re-running the query. Available in Tree View and Table View.

Search bar with Field/Value/Both mode selector and next/previous navigation
  • Three Search Modes: Field names only, Values only, or Both
  • Case-Insensitive: Finds matches regardless of capitalization
  • Highlights Matches: All matching text is highlighted in yellow
  • Navigation: Use Next/Previous buttons or Enter / Shift+Enter
  • Match Counter: Shows current match and total (e.g., "3 / 15")
  • Auto-Expand: Automatically expands nested objects to show matches
  • Cross-Column Search: Searches all visible columns simultaneously
  • Highlights Cells: Matching cells are highlighted
  • Scroll to Match: Automatically scrolls to show the current match
  • Works with Hidden Columns: Shows matches even in collapsed nested fields
Video COLL16 Using Inline Search Within Results - Discover how to search through query results without re-running queries. Open the search bar, choose a search mode (Field names, Values, or Both), type your search term to see matches highlighted instantly. Use Next/Previous buttons or Enter/Shift+Enter to navigate between matches. Watch how the match counter updates and nested objects auto-expand to reveal matching content.

Pagination Controls

Navigate through large result sets with flexible pagination options.

Bottom pagination bar showing document count, page navigation, and documents-per-page selector

Pagination Features

  • Document Counter: Shows "Displaying X - Y of Z documents" or filtered count
  • First/Previous/Next/Last: Navigation buttons for jumping between pages
  • Documents Per Page: Choose 50, 100, 200, 300, or 500 documents per page
  • Total Count Display: Shows total documents in collection vs. filtered count
  • Smart Loading: Only fetches the current page of results

Performance Tip: For large collections, use smaller page sizes (50-100 documents) for faster loading. Combine with query filters and indexes for optimal performance.

Context Menu Actions

Right-click on documents, fields, or values to access contextual actions.

Document-Level Actions

  • Edit Document - Open document in JSON editor dialog
  • Delete Document - Remove document from collection (requires confirmation)
  • Duplicate Document - Create a copy with a new _id
  • Copy Document - Copy entire document as JSON
  • Copy as EJSON - Copy with type information preserved
  • Refresh - Reload this specific document from the database

Field-Level Actions

  • Add Field - Insert a new field in the document or nested object
  • Rename Field - Change the field name
  • Delete Field - Remove the field from the document
  • Edit Value - Modify the field's value
  • Copy Field Name - Copy the field key
  • Copy Field Path - Copy dot-notation path
  • Copy Value - Copy only the field's value

Selection Actions (Table View)

  • Batch Update - Apply same update to all selected documents
  • Batch Delete - Delete all selected documents
  • Export Selection - Export only the selected documents
  • Copy Selected - Copy selected documents as JSON array

Keyboard Shortcuts

Shortcut Action Context
Enter Run query Query field focused
Ctrl+Space Trigger auto-complete Query editor
Ctrl+Z Undo last edit After document edit
Ctrl+Shift+Z Redo last undone edit After undo
Ctrl+V Paste document from clipboard When editable mode enabled
Esc Cancel inline edit During inline editing
Enter Next search result Search box focused
Shift+Enter Previous search result Search box focused
Shift+Click Select range of rows Table View

Note: On macOS, use Cmd instead of Ctrl

Query History & Saved Queries

Query History

Automatic tracking of all executed queries per collection.

  • Access via History button in toolbar
  • Shows recent queries with timestamp and execution time
  • Click any query to load it back into the Query field
  • Filter history by date or search term
  • Clear history for specific collections or all

Saved Queries

Save frequently used queries for quick access.

  • Save current query via dropdown menu
  • Give queries descriptive names
  • Organize queries by collection or globally
  • Export/import query collections as JSON
  • Share queries with team members
  • Load saved query to restore all parameters (query, projection, sort, limit, skip)

Open In Menu

Quickly switch to related tools while preserving context (database and collection).

Open In dropdown menu showing all available tools organized by category

Query Tools

  • Aggregation Pipeline: Build complex aggregation pipelines
  • MongoDB Shell: Execute shell commands and scripts
  • SQL Query Mode: Write SQL queries that translate to MongoDB

View & Analysis

  • Collection Statistics: View detailed collection metrics and index usage
  • Create Chart: Visualize query results with 20+ chart types

Data Transfer

  • Import Data: Import JSON, CSV, or BSON files into this collection
  • Export Data: Export query results to various formats

Pro Tips

  1. Use Indexes for Performance: Check Explain View to see if your queries use indexes. Add indexes for frequently queried fields to dramatically improve performance.
  2. Projection Reduces Network Load: Use projection to return only the fields you need. This reduces bandwidth and speeds up queries, especially for documents with large nested objects.
  3. Test Queries on Smaller Limits First: When working with large collections, start with a small limit (e.g., 10 or 50) to verify your query works before fetching thousands of documents.
  4. Copy Field Paths for Nested Queries: Right-click any nested field and select "Copy Field Path" to get the correct dot-notation for use in queries (e.g., user.profile.email).
  5. Use BSON View to Verify Types: When debugging type-related issues or preparing for import/export, switch to BSON View to see the exact BSON types of your data.
  6. Save Complex Queries: Don't re-type complex queries! Use the Save Query feature to store frequently used queries and share them with your team.
  • Aggregation Pipeline Builder - For complex data transformations beyond simple queries, use the visual aggregation pipeline builder
  • MongoDB Shell - Execute any MongoDB command or script with full shell access
  • Index Management - Create and manage indexes to optimize query performance
  • JSON Schema Activity - Validate documents against JSON schemas and find non-compliant documents
  • Chart Builder - Visualize query results with interactive charts and dashboards
  • Export Data - Schedule recurring exports or perform bulk imports with field mapping

Ready to try VisuaLeaf?

Download and start managing your MongoDB databases with ease.

Download Free Trial