SQL INPUT
MONGODB OUTPUT
// MongoDB query will appear here...
// Try an example

What is this SQL to MongoDB Converter?

This tool translates standard SQL queries into the equivalent syntax used by MongoDB, a document-oriented NoSQL database. It is built for developers who are migrating away from a relational database, or who work with both worlds at the same time.

Type your SQL query in the input panel and the matching MongoDB query appears alongside it. A real SQL parser handles the query, so complex WHERE clauses and basic aggregations are converted correctly rather than guessed at.

The converter is built on an SQL parsing library, which lets it handle a broad range of statements:

SELECT

find() — basic query

Column selection and WHERE conditions become a MongoDB find() call with a query filter and a projection.

SELECT name, age FROM users WHERE age > 25 db.users.find( { age: { $gt: 25 } }, { name: 1, age: 1, _id: 0 } )
SELECT

sort(), limit(), skip()

ORDER BY becomes sort(), LIMIT becomes limit(), and OFFSET becomes skip().

SELECT * FROM products ORDER BY price DESC LIMIT 10 OFFSET 20 db.products.find({}) .sort({ price: -1 }) .skip(20).limit(10)
AGGREGATE

GROUP BY → aggregate()

GROUP BY combined with aggregate functions (COUNT, SUM, AVG, MIN, MAX) is translated into a MongoDB aggregation pipeline.

SELECT country, COUNT(*) AS total FROM users GROUP BY country db.users.aggregate([ { $group: { _id: { country: "$country" }, total: { $sum: 1 } } } ])
AGGREGATE

HAVING → $match after $group

A HAVING filter becomes a second $match stage in the pipeline, applied after the grouping has happened.

SELECT category, AVG(price) AS avg_p FROM products GROUP BY category HAVING AVG(price) > 50 → pipeline with $group then $match
WHERE

LIKE → $regex

SQL LIKE patterns using % (any characters) and _ (a single character) are converted into MongoDB regular expressions.

WHERE name LIKE '%mongo%' { name: { $regex: /.*mongo.*/ } } WHERE code LIKE 'IT_' { code: { $regex: /^IT.$/ } } NOT LIKE { field: { $not: /pattern/ } }
WHERE

IN, IS NULL, AND/OR

Full support for IN/$in, NOT IN/$nin, IS NULL, IS NOT NULL/$ne, AND/$and and OR/$or, including parentheses for grouping.

WHERE status IN ('a','b') { status: { $in: ["a","b"] } } WHERE deleted_at IS NULL { deleted_at: null } WHERE a=1 AND b=2 { $and: [{a:1},{b:2}] }
INSERT

insertOne() / insertMany()

A single-row INSERT becomes insertOne(); a multi-row INSERT becomes insertMany(). Column names become document field names.

INSERT INTO users (name, age) VALUES ('Alice', 30) db.users.insertOne({ name: "Alice", age: 30 })
UPDATE

updateMany() with $set

The SET clause becomes a MongoDB $set operator and the WHERE condition becomes the filter document.

UPDATE users SET status = 'active' WHERE id = 42 db.users.updateMany( { id: 42 }, { $set: { status: "active" } } )
DELETE

deleteMany()

DELETE FROM with a WHERE condition becomes deleteMany(). Handle with care: without a WHERE clause, every document is removed.

DELETE FROM sessions WHERE expires < '2024-01-01' db.sessions.deleteMany({ expires: { $lt: "2024-01-01" } })

SQL → MongoDB operator reference

SQL operator MongoDB operator Notes
=$eq (or implicit)Exact match
!= / <>$neNot equal
>$gtGreater than
>=$gteGreater than or equal
<$ltLess than
<=$lteLess than or equal
IN (...)$inValue in list
NOT IN (...)$ninValue not in list
LIKE '%x%'$regex: /.*x.*/% becomes .*, _ becomes .
NOT LIKE$not: /pattern/Negated regular expression
IS NULLfield: nullAlso matches missing fields
IS NOT NULL$ne: nullField exists and is not null
AND$andAll conditions must match
OR$orAny condition may match
COUNT(*)$sum: 1Inside the $group stage
SUM(f)$sum: "$f"Inside the $group stage
AVG(f)$avg: "$f"Inside the $group stage
MIN(f)$min: "$f"Inside the $group stage
MAX(f)$max: "$f"Inside the $group stage
ORDER BY ASCsort({ f: 1 })Ascending
ORDER BY DESCsort({ f: -1 })Descending
LIMIT nlimit(n)
OFFSET nskip(n)

Why convert SQL to MongoDB?

Database migration

Moving from MySQL, PostgreSQL, SQL Server or SQLite to MongoDB? Translate your existing query logic quickly and reduce the risk of mistakes during the migration.

Learning MongoDB

If you already know SQL, seeing each concept mapped side by side is the fastest route to the MongoDB query language and the document model behind it.

Everyday development

Even experienced MongoDB developers often think in SQL first. Use the converter as a quick reference to turn that mental model into correct syntax.

Team collaboration

Share converted queries with colleagues coming from a relational background. A shared reference removes friction between two different database cultures.

Frequently asked questions

How do I convert a SQL query to MongoDB?

Paste your SQL statement into the input panel and press Convert. The tool parses the SQL and returns the equivalent MongoDB shell command: SELECT becomes find(), WHERE conditions become a query filter, ORDER BY becomes sort(), and LIMIT and OFFSET become limit() and skip(). No registration or installation is required.

What is the MongoDB equivalent of SQL LIKE?

MongoDB has no LIKE keyword; pattern matching is done with $regex. A SQL % wildcard becomes .* and a SQL _ wildcard becomes a single dot. So WHERE name LIKE '%mongo%' converts to { name: { $regex: /.*mongo.*/ } }, and NOT LIKE is wrapped in $not.

What is the MongoDB equivalent of GROUP BY?

GROUP BY maps to an aggregation pipeline with a $group stage. The grouped columns become the _id of that stage and the aggregate functions become accumulators: COUNT(*) becomes { $sum: 1 }, SUM(field) becomes { $sum: "$field" }, and AVG, MIN and MAX map to $avg, $min and $max. A HAVING clause becomes a second $match stage placed after $group.

Does this converter support SQL JOINs?

Not automatically. A JOIN in MongoDB requires a $lookup stage plus a decision about whether the related data should be embedded or referenced, and that depends on your schema design rather than on the SQL alone. Convert single-table queries here and add the $lookup stage yourself.

Can I migrate data from MySQL or SQL Server to MongoDB with this tool?

No. This converter translates query syntax, not data. To move the rows themselves you need a migration tool such as MongoDB Relational Migrator, which is free and supports Oracle, SQL Server, MySQL and PostgreSQL. Use this converter alongside it to translate the queries already embedded in your application code.

Is this SQL to MongoDB converter free?

Yes. The tool is completely free, runs in your browser, requires no account and stores none of your queries. It is available in English, Italian, Russian, Chinese, French and Spanish.

Planning a migration, not just a query?

Converting queries is the last step. These guides cover the part that decides whether a migration succeeds: how to reshape a relational schema into documents.