SQL to MongoDB Query Converter
Convert SQL queries to MongoDB find(), aggregate(), updateMany() and more, for mongosh or Mongoose.
How to convert SQL to a MongoDB query
- Paste a SQL query, or pick one of the examples above the editor.
- Choose mongosh for the shell and Compass, or Mongoose for Node.js code.
- Copy the result. You can paste several statements separated by semicolons.
The converter runs in your browser, so table names and values stay on your computer.
What SQL is supported
| SQL | MongoDB result |
|---|---|
SELECT … WHERE … ORDER BY … LIMIT |
find(filter, projection).sort().skip().limit() |
=, !=, >, >=, <, <= |
$eq, $ne, $gt, $gte, $lt, $lte |
AND, OR, NOT |
Merged filters, $or, $nor |
IN, NOT IN, BETWEEN |
$in, $nin, $gte + $lte |
LIKE '%phone%' |
Regular expression /phone/i |
IS NULL, IS NOT NULL |
null, { $ne: null } |
COUNT(*) |
countDocuments() |
SELECT DISTINCT col |
distinct() |
GROUP BY with COUNT, SUM, AVG, MIN, MAX, HAVING |
aggregate() with $group, $project and $match |
INNER JOIN / LEFT JOIN |
$lookup + $unwind |
INSERT, UPDATE, DELETE |
insertOne/insertMany, updateMany with $set/$inc, deleteMany |
SQL words and their MongoDB names
A table is a collection, a row is a document, and a column is a field. The SQL primary key id is _id in MongoDB, which is why the “Map id to _id” option is on by default. Text that looks like an ObjectId becomes ObjectId("…"), and date text becomes ISODate("…") so comparisons work on real dates.
Things to check after converting
LIKE becomes a regex. A pattern that starts with % can’t use an index, so it scans the whole collection. Prefer prefix searches such as 'abc%', or use a text or Atlas Search index for full-text search.
NULL behaves a little differently. { field: null } matches documents where the field is null and documents where the field doesn’t exist at all.
Think twice before copying JOIN-heavy designs. MongoDB can join with $lookup, but data that is always read together is usually better stored together in one document.
Frequently asked questions
Can it convert subqueries?
Not yet. Run the inner query first and paste its results into an IN (…) list, or rewrite it as a JOIN, which converts to $lookup.
Is the Mongoose output different from mongosh?
The filters are the same. The Mongoose version calls methods on a model such as User, adds await, and leaves ObjectId strings as plain strings because Mongoose converts them for you.
Is LIKE case-sensitive?
MySQL usually compares text without case, so the converter adds the i flag by default. Untick “Case-insensitive LIKE” for exact case matching.
More free tools
-
JSON to Mongoose Schema Converter
Paste a JSON document and get a ready-to-use Mongoose schema and model, with nested schemas, ObjectId refs and timestamps.
-
JSON to Zod Schema Generator
Turn any JSON into a Zod schema plus its TypeScript type, ready to validate API responses and form data.
-
JSON to TypeScript Interface Generator
Generate clean TypeScript interfaces from JSON in one paste, including nested objects, arrays and optional fields.
-
PAN, Aadhaar, GST and IFSC Validator
Check PAN, Aadhaar, GSTIN, IFSC, PIN code, mobile and UPI formats, with real checksum tests and copy-ready regex.
-
MongoDB Connection String Checker and Builder
Find what’s wrong with a MongoDB URI, from unencoded passwords to SRV ports, or build a correct one for Atlas or a local server.
-
MongoDB ObjectId to Timestamp Converter
See when any MongoDB document was created from its _id, or turn a date into an ObjectId for fast range queries.
