Loading MongoDB to SQL Converter...
Please wait a moment

MongoDB to SQL Converter Online — Convert MongoDB Queries to SQL Statements

Paste your MongoDB query above and get the equivalent SQL instantly — find() to SELECT, aggregate pipelines to JOINs and GROUP BY, insert/update/delete operations and more. Everything runs in your browser, so your queries never leave your machine.

How to Convert MongoDB to SQL — Step-by-Step

Step 1

Input Your MongoDB Query

Have a MongoDB query you need in SQL? Three ways to get it in:

Paste directly: Copy your MongoDB query and paste it into the input editor — conversion happens instantly
Upload a file: Click "Upload" to select a .js or .txt file containing your MongoDB query
Load a sample: Click "Sample" to see an example with an aggregate pipeline that includes $lookup, $match, $group, and $sort

Example: MongoDB find() Query

A simple MongoDB find query with a filter condition:

db.users.find({
  status: "active"
})
Step 2

Automatic Conversion to SQL

No button press needed — the converter runs the moment you paste. It maps MongoDB query operators to standard SQL syntax. The MongoDB query above produces:

Collection to table: The MongoDB collection name becomes the SQL table name in the FROM clause
Filter to WHERE: MongoDB query conditions are translated to SQL WHERE clauses with proper operators
Syntax highlighted output: The SQL output is color-coded for easy reading

Example: Equivalent SQL Output

The MongoDB find query converted to a SQL SELECT statement:

SELECT *
FROM users
WHERE status = 'active';
Step 3

Advanced Queries — Aggregation to JOIN & GROUP BY

The converter handles complex aggregate pipelines too. A MongoDB pipeline with $lookup, $match, $group, and $sort becomes a full SQL query with JOINs, WHERE, GROUP BY, HAVING, and ORDER BY:

$lookup: Becomes LEFT JOIN with the referenced collection and matching fields
$group with $sum/$avg: Becomes GROUP BY with SUM(), AVG(), COUNT(*)
$match after $group: Becomes a HAVING clause for filtering grouped results

Example: Aggregate Pipeline to SQL

A MongoDB aggregate with $lookup and $group converts to:

SELECT name,
       email,
       COUNT(*) AS order_count,
       SUM(orders.total) AS total_spent
FROM users
LEFT JOIN orders ON users._id = orders.user_id
WHERE status = 'active'
GROUP BY name, email
HAVING order_count > 5
ORDER BY total_spent DESC
LIMIT 10;
Step 4

Copy or Download Your SQL

When the SQL looks right, grab it:

Copy to clipboard: One-click copy to paste directly into your SQL client, database tool, or code editor
Download as .sql file: Save the converted SQL as a .sql file for your project or version control
Keep working: Try other tools like JSON Formatter, JSON to CSV, or JSON Editor

Frequently Asked Questions — MongoDB to SQL Converter

How do I convert MongoDB queries to SQL?

Just paste your MongoDB query in — the converter runs immediately and outputs the equivalent SQL statement. It handles find(), aggregate(), insert, update, and delete operations. No account, no button to click, nothing to install.

What MongoDB operations are supported?

The converter supports find(), findOne(), aggregate() with pipeline stages ($match, $group, $lookup, $project, $sort, $limit, $skip, $count), insertOne(), insertMany(), updateOne(), updateMany(), deleteOne(), deleteMany(), countDocuments(), and distinct().

Can it handle aggregate pipelines with $lookup and $group?

Yes. $lookup becomes a LEFT JOIN, $group becomes GROUP BY with aggregate functions (SUM, AVG, COUNT, MIN, MAX), $match after $group becomes a HAVING clause, and $sort becomes ORDER BY.

What MongoDB query operators does it support?

The converter handles $gt, $gte, $lt, $lte, $ne, $eq, $in, $nin, $regex (to LIKE), $exists (to IS NULL / IS NOT NULL), $and, $or, and $nor.

Are there MongoDB features that cannot be converted to SQL?

Some MongoDB-specific features like deeply nested document queries, $unwind on embedded arrays, geospatial queries, and text search do not have direct SQL equivalents. The converter focuses on the most common patterns that map cleanly between MongoDB and relational databases.

Is my data safe? Does this tool send queries to a server?

All conversion happens locally in your browser. Your MongoDB queries are never sent to any server — fully private and secure. No data leaves your machine.

Is this converter free to use?

Completely free, no account needed, no usage limits. Convert as many MongoDB queries as you want.