Monitoring
Solutions
Resources
Free Tools
Pricing
Free Tools / Converters / SQL to MongoDB Converter

SQL to MongoDB Converter

Write the query in SQL and get the MongoDB shell command that does the same: find() with a filter and projection, an aggregation pipeline for GROUP BY, or insertMany, updateMany and deleteMany.

Runs entirely in your browser — nothing you enter here is sent to a server.

SQL and MongoDB, side by side

If you know SQL, you already know what you want from MongoDB — the difficulty is the syntax. MongoDB expresses a query as a document rather than a sentence: conditions are nested objects, operators start with a dollar sign, and anything involving grouping moves into an aggregation pipeline. This converter translates the SQL you can write into the MongoDB you are trying to remember.

SQLMongoDB
WHERE a = 1 AND b > 2{ a: 1, b: { $gt: 2 } }
WHERE a = 1 OR b = 2{ $or: [{ a: 1 }, { b: 2 }] }
IN (…) / NOT IN (…)$in / $nin
LIKE 'An%'{ $regex: "^An", $options: "i" }
BETWEEN 1 AND 5{ $gte: 1, $lte: 5 }
IS NULL / IS NOT NULLnull / { $ne: null }
SELECT a, bprojection { a: 1, b: 1, _id: 0 }
ORDER BY a DESC LIMIT 10 OFFSET 20.sort({ a: -1 }).skip(20).limit(10)
COUNT(*) … GROUP BY aaggregate([{ $group: { _id: "$a", count: { $sum: 1 } } }])

What translates and what does not

Single-table statements translate cleanly: SELECT with conditions, sorting and paging; COUNT, SUM, AVG, MIN and MAX with or without GROUP BY; DISTINCT; and INSERT, UPDATE and DELETE. Joins and subqueries are reported as unsupported rather than guessed at — not because MongoDB cannot do them ($lookup exists) but because a join usually signals a relational design, and in a document database the better answer is often to embed the related data.

Dates are not strings

A date written as '2026-01-01' is translated as a string. If the field holds real dates, wrap the value: ISODate("2026-01-01").

LIKE becomes a regex

A pattern anchored at the start ('An%') can use an index; a leading wildcard ('%an') scans the collection, just as in SQL.

NULL also matches "missing"

{ field: null } matches documents where the field is null and those where it does not exist.

UPDATE and DELETE affect many

They become updateMany and deleteMany. Without a WHERE the filter is {} — every document.

Frequently asked questions

How do I write a SQL WHERE clause in MongoDB?

As a filter document passed to find(). Equality is { field: value }; other comparisons use operators such as $gt, $lte, $ne and $in; AND is several keys in one document; OR is { $or: [ … ] }.

What is the MongoDB equivalent of GROUP BY?

The $group stage of an aggregation pipeline. The grouping column goes in _id, and each aggregate becomes an accumulator such as $sum or $avg. A WHERE clause becomes a $match stage before it.

Can it convert JOINs?

No. Joins require $lookup in an aggregation pipeline and usually a rethink of the data model, so the converter reports them instead of producing something misleading.

Does the query run against my database?

No. The converter only translates text in your browser. Copy the result into mongosh or your driver and run it yourself.

Related free tools

A calculator answers once. Monitoring answers every minute.

Upzilla checks your sites, servers and APIs around the clock and alerts you the moment something breaks. 10 monitors free, no card required.

Start monitoring free →