SQL to MongoDB Query Converter
Convert SQL SELECT statements to MongoDB find() and aggregate() queries instantly.
Frequently Asked Questions
This tool supports basic SELECT statements including column selection, WHERE clauses (=, !=, >, <, >=, <=, LIKE, IN, AND, OR, NOT, IS NULL, IS NOT NULL, BETWEEN), ORDER BY, LIMIT, OFFSET/SKIP, GROUP BY with aggregate functions, COUNT(*), and basic JOINs converted to $lookup.
Basic INNER JOINs are converted to MongoDB's $lookup aggregation stage. The tool generates an aggregate pipeline with $lookup specifying the foreign collection, localField, foreignField, and output alias. Complex joins with multiple conditions may need manual adjustment.
MongoDB's find() is used for simple queries with filters, projections, sorts, skips, and limits. The aggregate() pipeline is used for more complex operations like GROUP BY, JOINs ($lookup), computed fields, and multi-stage data transformations.
SQL LIKE patterns are converted to MongoDB $regex. The '%' wildcard becomes '.*' and '_' becomes '.'. For example, LIKE '%test%' becomes { $regex: '.*test.*', $options: 'i' }. The 'i' flag makes it case-insensitive by default.
This tool handles single-level SELECT statements. Nested subqueries, UNION, HAVING, window functions, and CTEs are not supported. For those, you would need to manually structure the MongoDB equivalent using multiple queries or aggregation stages.