DevKit
Converter

SQL to MongoDB

Convert SQL queries to MongoDB shell commands.

Last updated: August 2026

Supports SELECT, INSERT, UPDATE, DELETE with basic WHERE clauses.

Share:

Was this tool helpful?

Translating a query to the Mongo shell

This converter maps a SQL statement onto the MongoDB shell equivalent. A table becomes a collection, a row a document, a WHERE clause a filter object, and SELECTed columns a projection. It helps when you know relational SQL fluently but are new to Mongo's method-and-document style, so you can see the shape of the same question in both languages.

When you reach for it

Useful when migrating a feature from a SQL store to Mongo, when prototyping a query you already wrote in SQL, or when reading a Mongo codebase and wanting to anchor each find call against the SQL you already understand.

Example

-- SQL
SELECT name, email
FROM users
WHERE age > 21 AND active = true
ORDER BY name
LIMIT 10;

// MongoDB
db.users.find(
  { age: { $gt: 21 }, active: true },
  { name: 1, email: 1, _id: 0 }
).sort({ name: 1 }).limit(10)

Comparison operators become $gt, $lt, and friends, and the second argument to find is the projection.

Common pitfalls

Projection surprises people: Mongo returns _id by default, so you must explicitly set _id: 0 to match a SQL SELECT that never asked for it. SQL JOINs have no one-line equivalent; you either denormalize or use an aggregation $lookup, which is far more verbose than a join. And NULL semantics differ: a SQL column IS NULL is not the same as a field being absent in Mongo, where a document may simply omit the key, so $exists and equality to null mean different things.

FAQ

Why does _id keep appearing? Mongo includes it unless you suppress it with _id: 0 in the projection.

How do I convert a JOIN? There is no direct form. Use $lookup in an aggregation pipeline, or rethink the schema toward embedding.

Is COUNT(*) the same? Close: db.users.countDocuments({}) counts matching documents, and an empty filter counts everything.