SQL Mode is a translation layer for MongoDB. Write SELECT, WHERE, ORDER BY, GROUP BY and JOIN, and VisuaLeaf turns it into a native find() call or aggregation pipeline that runs on your MongoDB server. The MongoDB Query tab shows exactly what your SQL became. Connecting to PostgreSQL, MySQL or SQL Server instead? That is a different tool, the SQL Editor, covered further down this page.
Write SQL SELECT statements against your collections: WHERE, ORDER BY, LIMIT and OFFSET, DISTINCT, aliases, and aggregate functions such as COUNT, SUM, AVG, MIN and MAX. The editor autocompletes SQL keywords, collection names and field names, marks errors inline, and shows results in Tree, Table or BSON view.
Simple SELECTs become db.collection.find() calls; GROUP BY, JOIN and functions become aggregation pipelines. Switch to the MongoDB Query tab to read the generated filter or pipeline next to your SQL. It is a practical way to learn MongoDB syntax from queries you already know how to write.
Press F1 for the SQL Helper: tabs for basics, operators, functions, aggregation, JOINs, MongoDB types and advanced queries. Each example shows the SQL, the MongoDB operation it produces and a short explanation, with buttons to copy it or insert it straight into the editor.
SQL Mode only runs against MongoDB. If your data lives in a relational database, VisuaLeaf connects to it directly as a SQL client: try it as a MySQL GUI for Linux, a PostgreSQL GUI, a SQL Server GUI for Mac and Linux, a MariaDB GUI, or a SQLite GUI for Mac.
VisuaLeaf parses the SQL you write and runs the MongoDB equivalent. These pairs come from the SQL Mode documentation.
WHERE becomes the filter document, the column list becomes the projection, ORDER BY becomes the sort, and LIMIT and OFFSET map to limit and skip.
Aggregate functions, GROUP BY and HAVING are translated into aggregation pipeline stages.
INNER JOIN and LEFT JOIN are translated to $lookup stages, and you can chain several joins. Because $lookup can be expensive on large collections, index the join fields, for example orders.user_id.
SQL Mode covers the read side of SQL, adapted to MongoDB's document model. Knowing the limits up front saves time.
Some MongoDB behavior also differs from a relational database: field names are case-sensitive, dotted names such as address.city reach into nested documents, and MongoDB treats a null field and a missing field differently.
VisuaLeaf has two places to write SQL, and they point at different databases.
For querying MongoDB collections with SQL syntax. Your SQL is translated to find() or an aggregation pipeline and runs on MongoDB. Read-only, with the translation always visible in the MongoDB Query tab. Results can be turned into a chart with Create Chart or saved to the query library.
For relational databases. The SQL Editor runs native SQL in each database's own dialect, with autocomplete for tables and columns, multiple tabs, and F5 to run everything, F9 to run a selection or Ctrl/Cmd+F5 to run up to the cursor. Results open in Grid, Tree, JSON or Explain view, and a batch or stored procedure that returns several result sets shows each one in its own tab.
Pair it with the visual SQL query builder and ER diagrams. Read the SQL Editor documentation.
SELECT * FROM customers WHERE status = 'active'. Press F1 any time for the SQL Helper.$lookup stage in an aggregation pipeline. INNER and LEFT joins are supported; RIGHT and FULL OUTER joins are not. Index the fields you join on, because $lookup can be slow on large collections.WHERE _id = 'ObjectId("507f1f77bcf86cd799439011")' or WHERE created_at >= 'ISODate("2023-01-01T00:00:00.000Z")'. NumberLong, NumberDecimal, UUID and regular expressions work the same way.Choose your preferred query style: SQL Mode for familiar SELECT syntax or the Visual Query Builder for MongoDB-native queries. Both produce the same results - pick what feels natural. Great for teams transitioning from SQL databases to MongoDB.
SQL Mode supports GROUP BY and aggregate functions, but for advanced transformations use the Aggregation Pipeline. Start with SQL for simple aggregates, then graduate to the pipeline builder for $unwind, $lookup, and complex multi-stage operations.
Check out the documentation to explore all the details about SQL Mode and discover more VisuaLeaf features.
Read the DocumentationGet started free with our Community Edition. Includes a 14-day trial of Pro features.