Developer Tools
SQL to MongoDB Query Converter
Translate SQL into MongoDB queries — SELECT with WHERE (AND/OR, IN, LIKE, BETWEEN, IS NULL), ORDER BY, LIMIT, GROUP BY aggregations, plus INSERT, UPDATE and DELETE.
How to use
- 1Paste a SQL statement.
- 2Copy the equivalent MongoDB shell query.
How it's calculated
WHERE clauses become filter documents ($gt, $in, $regex for LIKE, $or/$and), columns become projections, ORDER BY → sort, LIMIT/OFFSET → limit/skip, and GROUP BY with COUNT/SUM/AVG/MIN/MAX becomes an aggregation pipeline.
Frequently asked questions
Does it support JOINs?
Not yet — JOINs map to $lookup stages, which depend on how your documents are modeled. Single-table queries are supported.
How is LIKE translated?
To a case-insensitive $regex: '%son' becomes 'son$', 'a_c%' becomes '^a.c'.
Can I use it for mongosh and drivers?
The output is mongosh syntax; drivers accept the same filter and pipeline documents.
Worked example: SQL to MongoDB Query Converter
SELECT name, email FROM users WHERE age >= 18 AND country IN ('US','CA') ORDER BY name DESC LIMIT 10 becomes db.users.find({"$and":[{"age":{"$gte":18}},{"country":{"$in":["US","CA"]}}]}, {"name":1,"email":1,"_id":0}).sort({"name":-1}).limit(10) — notice the projection automatically adds "_id": 0, since SQL's SELECT name, email implies you don't want MongoDB's default _id field included, which MongoDB would otherwise return even when you didn't ask for it. A GROUP BY query — SELECT status, COUNT(*) AS n FROM orders WHERE total > 100 GROUP BY status ORDER BY n DESC — takes an entirely different shape: a three-stage aggregate() pipeline ($match, $group, $sort), because SQL's GROUP BY has no direct equivalent in MongoDB's query-filter syntax — grouping and aggregation only exist in the pipeline framework.
Why LIKE becomes a regex, and what that changes
SQL's LIKE has exactly two wildcards (% for any sequence, _ for one character), while MongoDB has no LIKE operator at all — the translator converts '%@test.com' into the regex pattern @test\.com$ (anchored at the end, with the literal dot escaped so it doesn't match any character) wrapped in a case-insensitive $regex. That case-insensitivity is a deliberate default, not something the original SQL necessarily specified — standard SQL LIKE is case-sensitive in most databases (MySQL being a notable exception depending on collation), so if your original query relied on case-sensitive matching, double-check the translated $regex's options before trusting it to behave identically.
Why joins are the one thing this can't translate
A SQL JOIN is a relational operation with no single MongoDB equivalent — it could become a $lookup stage, or it could mean the data should actually be embedded as a sub-document instead of joined at query time, and which approach is correct depends entirely on how you've modeled your MongoDB schema, information a SQL string alone doesn't contain. That's a genuine modeling decision, not a mechanical translation, which is why the tool explicitly refuses to guess and errors out on any query containing JOIN rather than producing a $lookup pipeline that might not match how your collections are actually structured.
An empty query stays empty, and a trailing semicolon is fine
A blank box produces a blank result. A query the translator cannot handle stops and shows the reason. The sample in the box is a select of name and email from users, with an age test, a country list, an order, and a limit. The same query with a semicolon on the end still converts, so I do not have to delete the semicolon I copied from a script. I clear the box when I want to start over and expect silence, not an error about a missing select. I leave the semicolon in place.
Related tools
- SQL Formatter
Format and beautify SQL queries for PostgreSQL, MySQL, SQL Server, SQLite, BigQuery and more, with uppercase keywords.
- CSV to SQL INSERT Generator
Generate SQL CREATE TABLE and INSERT statements from CSV data for MySQL, PostgreSQL, SQLite or SQL Server.
- JSONPath Tester
Query JSON with JSONPath expressions like $.store.book[*].author or $..price and see every match with its exact path.
- URL Encode / Decode
Percent-encode text for URLs and query strings, or decode %20-style encoded URLs back into readable text.
- String Escape / Unescape
Escape or unescape strings for JavaScript, JSON, HTML, XML, SQL, CSV and regular expressions — quotes, backslashes and newlines handled.
- SQL Playground (SQLite Online)
Practice and run SQL in your browser on a real SQLite database — sample shop data included, joins, CTEs and window functions, import CSV/Excel as tables, open .db files and export results.