SQL → MongoDB find()

Translate a basic SELECT/WHERE/LIMIT SQL into a MongoDB find() call.

Open tool

Overview

The SQL-to-MongoDB converter translates a basic SELECT ... FROM ... WHERE ... LIMIT SQL statement into the equivalent MongoDB find() call. Projection, filters, sorting, and limits are mapped to their MongoDB query operator counterparts.

It's a learning aid for developers coming from a SQL background to MongoDB and a quick reference when sketching a query in SQL because that's what comes to mind first. Backend developers prototyping a MongoDB query reach for a sql to mongo converter to bridge the syntax gap without consulting the docs.

How it works

SQL columns in the SELECT list become a projection object in MongoDB: SELECT name, email produces { name: 1, email: 1, _id: 0 }. The WHERE clause is translated into a filter object: equality becomes { field: value }; comparisons use $gt, $gte, $lt, $lte; IN becomes $in; LIKE patterns translate to anchored regular expressions; AND is implicit, OR becomes $or.

ORDER BY becomes .sort({...}) with 1 for ascending and -1 for descending. LIMIT becomes .limit(n); OFFSET becomes .skip(n). Joins, aggregations, and subqueries are not supported — they need $lookup and aggregate() pipelines that are too dialect-specific for a one-liner.

Examples

SELECT name, email
FROM users
WHERE age > 30 AND active = TRUE
ORDER BY created_at DESC
LIMIT 10
db.users.find(
  { age: { $gt: 30 }, active: true },
  { name: 1, email: 1, _id: 0 }
)
.sort({ created_at: -1 })
.limit(10)
SELECT * FROM products WHERE name LIKE '%phone%'
db.products.find({ name: { $regex: "phone", $options: "i" } })

FAQ

What about JOINs?

MongoDB joins use the $lookup aggregation stage, not find(). The converter focuses on single-collection queries; for multi-collection workflows, hand-write the pipeline or use the SQL-to-MongoDB-aggregate path in tools like Studio 3T.

Does it support aggregations like SUM and GROUP BY?

Not in this converter. Those require the aggregate() pipeline with $group, $sum, and $project stages, which differ significantly from the simple find() shape.

How are LIKE patterns translated?

LIKE '%foo%' becomes { $regex: "foo", $options: "i" }. LIKE 'foo%' becomes { $regex: "^foo", $options: "i" }. Underscore wildcards (_) translate to regex .; literal % and _ in patterns can be escaped with \.

Try SQL → MongoDB find()

An unhandled error has occurred. Reload ×