SQL Query Mode
SQL Mode is a translation layer that lets you query your MongoDB collections using familiar SQL syntax. Under the hood, VisuaLeaf parses your SQL and translates it into an equivalent MongoDB find() or aggregation pipeline that runs against your MongoDB server. Great for developers coming from a relational background who want to explore MongoDB without learning the native query DSL first.
Looking for native SQL database support? If you want to connect VisuaLeaf directly to PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, or SQLite, see the SQL Support section in the sidebar — those pages cover the SQL Editor, Visual SQL Query Builder, Table Activity, System Monitor, Profiling, User Management, and more. This page is exclusively about the SQL → MongoDB translator.
Execute your first SQL query in seconds:
SELECT * FROM customers WHERE status = 'active')
The left panel contains the Monaco SQL editor with advanced features:
The right panel displays results in tabbed interface:
Control buttons and actions:
VisualLeaf automatically translates your SQL queries into MongoDB operations in real-time:
SELECT statements translate to db.collection.find()GROUP BY, JOIN, and functions translate to aggregation pipelinesWHERE clauses become MongoDB filter objectsORDER BY converts to MongoDB sort specificationsLIMIT and OFFSET map to skip/limit| SQL Query | MongoDB Translation |
|---|---|
SELECT * FROM users |
db.users.find({}) |
SELECT name, email FROM users WHERE age >= 18 |
db.users.find({age: {$gte: 18}}, {name: 1, email: 1}) |
SELECT COUNT(*) FROM orders GROUP BY status |
db.orders.aggregate([{$group: {_id: "$status", count: {$sum: 1}}}]) |
VisualLeaf supports a comprehensive subset of SQL syntax optimized for MongoDB operations:
SELECT * FROM collectionSELECT field1, field2, field3 FROM collectionSELECT name AS userName, age AS userAge FROM usersSELECT DISTINCT status FROM ordersFilter data using standard SQL operators:
=, !=, <, >, <=, >=AND, OR, NOTBETWEEN x AND y, NOT BETWEENIN (value1, value2), NOT INLIKE 'pattern%', NOT LIKEIS NULL, IS NOT NULLORDER BY field ASCORDER BY field DESCORDER BY field1 ASC, field2 DESCLIMIT 10LIMIT 10, 20 (skip 10, return 20)OFFSET 10 LIMIT 20SELECT COUNT(*) FROM collectionSELECT SUM(amount) FROM ordersSELECT AVG(price) FROM productsSELECT MIN(price), MAX(price) FROM productsSELECT status, COUNT(*) FROM orders GROUP BY statusGROUP BY field1, field2HAVING COUNT(*) > 10SELECT * FROM users INNER JOIN orders ON users._id = orders.user_idSELECT * FROM users LEFT JOIN orders ON users._id = orders.user_idVisualLeaf supports a wide range of SQL functions that are translated to MongoDB aggregation operators:
CONCAT(first_name, " ", last_name)UPPER(name)SUBSTRING(text, 1, 10)LENGTH(name)REPLACE(phone, "-", "")ROUND(price, 2)ABS(balance)MOD(value, 10)YEAR(created_at)WHERE created_at > NOW()DATE_FORMAT(date, "%Y-%m-%d")IF(active, "Yes", "No")IFNULL(nickname, "Anonymous")COALESCE(nick, first, "Unknown")NULLIF(value, 0)SIZE_OF_ARRAY(tags)SELECT UNWIND(items) FROM ordersCAST(price AS STRING)Use MongoDB-specific types directly in your SQL queries:
Query by MongoDB ObjectId:
SELECT * FROM users WHERE _id = 'ObjectId("507f1f77bcf86cd799439011")'
Use ISO date format for date comparisons:
SELECT * FROM orders
WHERE created_at >= 'ISODate("2023-01-01T00:00:00.000Z")'
AND created_at < 'ISODate("2024-01-01T00:00:00.000Z")'
Handle large integers and precise decimals:
SELECT * FROM transactions WHERE amount = 'NumberLong("9007199254740993")'
SELECT * FROM prices WHERE value = 'NumberDecimal("19.99")'
Query by UUID fields:
SELECT * FROM sessions WHERE session_id = 'UUID("550e8400-e29b-41d4-a716-446655440000")'
Use regex patterns for advanced matching:
SELECT * FROM products WHERE name = '/^iPhone/i'
Press F1 or click the Help button to open the comprehensive SQL Helper modal with interactive examples.
| Tab | Contents |
|---|---|
| Basics | SELECT statements, WHERE clauses, ORDER BY, LIMIT |
| Operators | Comparison, range, pattern matching (LIKE), NULL operators |
| Functions | String, math, date, and conditional functions |
| Aggregation | COUNT, SUM, AVG, MIN, MAX, GROUP BY, HAVING |
| JOINs | INNER JOIN, LEFT JOIN examples and patterns |
| Types | MongoDB types: ObjectId, ISODate, NumberLong, UUID, regex |
| Advanced | Array functions, object operations, CASE expressions |
Each example in the SQL Helper includes:
While VisualLeaf supports most common SQL operations, there are some differences from standard SQL due to MongoDB's document-oriented nature:
BEGIN, COMMIT, ROLLBACK in queries (use MongoDB transactions directly)INSERT, UPDATE, DELETE statements (use Collection Activity for CRUD)CREATE TABLE, ALTER TABLE, DROP TABLEaddress.city)LIKE 'prefix%')-- Get all active users SELECT * FROM users WHERE status = 'active' -- Get specific fields SELECT name, email, created_at FROM users WHERE age >= 18
-- Count orders by status SELECT status, COUNT(*) AS order_count FROM orders GROUP BY status -- Average order value by customer SELECT customer_id, AVG(total) AS avg_order, SUM(total) AS total_spent FROM orders GROUP BY customer_id HAVING total_spent > 1000 ORDER BY total_spent DESC
-- Get users with their orders SELECT users.name, orders.total, orders.status FROM users INNER JOIN orders ON users._id = orders.user_id WHERE orders.status = 'pending' -- Include users without orders SELECT users.name, orders.total FROM users LEFT JOIN orders ON users._id = orders.user_id
-- Orders from last 30 days SELECT * FROM orders WHERE created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY) -- Orders in 2023 SELECT * FROM orders WHERE YEAR(created_at) = 2023
-- Full name from parts
SELECT CONCAT(first_name, ' ', last_name) AS full_name,
UPPER(email) AS email_upper
FROM users
WHERE email LIKE '%@gmail.com'
-- Products with tag count SELECT name, SIZE_OF_ARRAY(tags) AS tag_count FROM products WHERE SIZE_OF_ARRAY(tags) > 0 -- Flatten array of items SELECT order_id, UNWIND(items) AS item FROM orders
| Shortcut | Action |
|---|---|
| F5 | Execute SQL query |
| F1 | Open SQL Helper modal with examples and reference |
Note: On macOS, keyboard shortcuts work the same (F1, F5)
Save and organize your SQL queries for reuse:
Click the History button to access previously executed SQL queries:
Transform your query results into visual charts with one click:
LIMIT with large datasets to avoid slow queries. Start with LIMIT 100 to preview results quickly.WHERE date >= 'ISODate("2023-01-01")'Download and start managing your MongoDB databases with ease.
Download Free Trial