SQL to MongoDB Query
Translates SQL into MongoDB shell syntax: SELECT to find() or an aggregate pipeline, INSERT to insertOne and insertMany, UPDATE to updateMany with $set, and DELETE to deleteMany. LIKE becomes a regex.
Use the tool
Why this tool exists
Moving from a relational database to MongoDB, or just learning it from a SQL background, means translating every query. WHERE conditions become filter documents, ORDER BY becomes sort, GROUP BY with aggregates becomes a pipeline of $match, $group and $project stages, and a JOIN becomes $lookup. This tool does that mapping for you, so you can see how a familiar query looks in Mongo shell syntax. It is a learning aid and a first draft for migrations: it does not support subqueries, UNION or CTEs, and the translated query is never run. Check each result against your data model, because documents often are not shaped like your old tables. It runs in your browser.
How to use it
- Paste one or more SQL statements, one per paragraph, into the input box.
- Run the conversion to see the MongoDB commands.
- Copy the commands into the shell or your code and check them against your collections.
Frequently asked questions
Which statements are supported?
SELECT (with WHERE, ORDER BY, LIMIT, OFFSET, GROUP BY and simple JOINs), INSERT with VALUES, UPDATE and DELETE.
How does a join work?
Simple joins become a $lookup stage in an aggregate pipeline. Complex join conditions may need manual adjustment, and Mongo data models often embed instead of join.
What about LIKE?
LIKE patterns are translated into MongoDB regular expressions, so a condition such as email LIKE a wildcard pattern becomes a $regex filter. Check anchoring and case sensitivity on your own data.
What is not supported?
Subqueries, UNION and CTEs. The query is only translated, never executed, so test it on a copy of your data.