MongoDB Query Formatter
Format MongoDB shell queries and aggregation pipelines.
Your MongoDB queries are formatted locally in your browser and nothing is uploaded to a server.
Working with SQL too? Try the SQL Formatter.
About MongoDB Query Formatter
This online mongodb formatter cleans up dense MongoDB shell queries, filter objects, and aggregation pipelines into readable, properly indented code. Paste a one-line db.collection.find() call, a $match/$group pipeline, or a bare filter object, and it pretty-prints the result with consistent spacing, double quotes, and semicolons. As a mongo shell formatter it handles chained methods like sort, limit, and project, and you can switch between 2 and 4 space indentation. It is built for backend developers, database engineers, and QA testers who copy queries from logs, Compass, or chat threads and need to read, debug, or share them quickly. Everything is processed locally in your browser, so the queries you paste stay on your machine and nothing is uploaded to a server.
Features
- Formats db.collection.find(), update, and other chained shell statements
- Beautifies aggregation pipelines such as $match, $group, and $project stages
- Accepts bare filter objects and arrays, not just full statements
- Switch indentation between 2 and 4 spaces
- Normalizes spacing, double quotes, and semicolons via Prettier
- Preserves operators like $gt, $in, and $regex exactly as written
- Updates the formatted output live as you type or paste
- Download the formatted query as a .js file or copy it instantly
How to use the MongoDB Query Formatter
- Paste your MongoDB query, pipeline, or filter object into the input box.
- Choose 2 spaces or 4 spaces indentation in the toolbar.
- Read the formatted query in the output panel as it updates live.
- Copy the result or use Download to save it as query.js.
Example
Input
db.users.find({age:{$gt:18},active:true}).limit(5)
Output
db.users.find({ age: { $gt: 18 }, active: true }).limit(5);
A one-line find query reformatted with clean spacing.
Common errors & troubleshooting
- Pasting a query with unbalanced braces or parentheses returns a syntax error. — Make sure every {, [, and ( has a matching closing character before formatting.
- Trailing commas or shell prompt characters copied from a terminal break parsing. — Remove leading prompts and any dangling commas so the input is valid JavaScript.
- A bare object formats but a multi-statement script does not. — Format one statement or object at a time, or wrap multiple statements as a valid script.
- Single quotes in the input come back as double quotes. — This is expected: the formatter normalizes strings to double quotes for consistency.
Frequently asked questions
- What is the MongoDB formatter?
- The MongoDB formatter is an in-browser tool that pretty-prints MongoDB shell statements like db.collection.find(), aggregation pipelines, and bare filter objects or arrays with consistent indentation, spacing, and quoting.
- How do I format a MongoDB aggregation pipeline?
- Paste an array of stages such as $match, $group, and $sort into the MongoDB formatter and it pretty-prints each stage with clear nesting so the pipeline is easy to read.
- Can I control the indentation width in the MongoDB formatter?
- Yes, use the toolbar to switch between 2 and 4 spaces, and the formatted output updates immediately.
- Will the MongoDB formatter change my operators or values?
- No. Operators like $gt and $in and your field values are preserved; only whitespace, quoting, and semicolons are normalized for readability.
- Are my queries sent anywhere when I use this MongoDB formatter?
- No. Formatting runs entirely in your browser and your queries are never uploaded to a server, so nothing you paste leaves your device.
Related tools
- SQL Formatter — Format SQL for MySQL, PostgreSQL, SQL Server, SQLite, BigQuery and Oracle.
- GraphQL Formatter — Format or minify GraphQL queries and schemas, validate syntax and extract operations.
- JSON Formatter — Beautify, minify and validate JSON with error locations.
- JS / TS Formatter — Beautify or minify JavaScript, TypeScript and JSX/TSX with Prettier options.
- Dockerfile Formatter — Format a Dockerfile and get best-practice / lint suggestions.
- JSON Tree Viewer — Explore JSON as a collapsible, typed tree.
- YAML ↔ JSON — Convert YAML to JSON and back.
- JSON to Code — Generate Go, Rust, Python, Java, Kotlin, C# and TypeScript types from JSON.
All ArrayKit tools