Skip to content
100% local

SQL to MongoDB query

Convert a SQL SELECT statement into a MongoDB find() call or aggregation pipeline.

Input
Output

SQL to MongoDB query

Paste a SQL SELECT statement and this tool converts it into the equivalent MongoDB query — either a mongosh method call you can run in the shell, or a plain JSON query document for your own driver code. It reads the WHERE clause, ORDER BY, LIMIT and OFFSET and turns them into a MongoDB filter, sort, limit and skip, so "SELECT id, name FROM users WHERE age > 18 ORDER BY name DESC LIMIT 10" becomes a ready-to-run find() with the matching filter and sort objects.

It also understands aggregation. COUNT, SUM, AVG, MIN and MAX in the SELECT list combined with GROUP BY produce a $group stage followed by a $project stage that renames the grouped _id fields back to their original columns. A JOIN becomes a $lookup plus $unwind stage when "Convert JOIN to $lookup" is on — turn it off and the join is dropped instead, with a note explaining why. "Convert column names to camelCase" reshapes snake_case columns like first_name into firstName, matching typical Mongoose naming, and the indentation is yours to set.

Not every SQL construct has a clean MongoDB equivalent — subqueries, UNION, CASE expressions and HAVING don't map onto a single query or pipeline. Rather than silently producing a wrong query, the tool reports a clear error naming the unsupported construct, or, for things it can work around (an extra JOIN, a dropped HAVING, an ungrouped SELECT column), adds a short warning comment above the generated query explaining what changed.

Everything runs locally in your browser: the SQL is parsed and converted entirely on your device, and no query or schema ever leaves it. Copy the result, download it as a .txt file, or send it back into the input to keep refining the original query.

FAQ

Does it support JOINs?
A single JOIN converts into a $lookup plus $unwind stage in an aggregation pipeline when "Convert JOIN to $lookup" is on. RIGHT JOIN is converted as a LEFT JOIN, and additional JOINs beyond the first are noted as ignored.
What happens to GROUP BY and aggregate functions like COUNT or SUM?
They become a $group stage (with the right accumulator for each function) followed by a $project stage that restores the original column names, all inside an aggregation pipeline.
What SQL features are not supported?
Subqueries, UNION and CASE expressions have no direct MongoDB equivalent and produce a clear error instead of an incorrect query. HAVING is accepted but dropped with a warning, since it needs a second $match stage you add yourself.
Can I get a plain JSON query instead of a mongosh command?
Yes. Switch "Output as" to JSON query to get a query document (collection, operation, filter, and so on) you can parse or embed in your own code instead of a shell call.
Is my SQL uploaded anywhere?
No. The conversion runs entirely in your browser — your query, table names and data never leave your device.