MongoDB Query Beautifier
Beautify and indent MongoDB queries and find() statements in your browser.
This tool runs entirely in your browser. The MongoDB queries you paste never leave your device and nothing is uploaded to ArrayKit.
Beautify an aggregation pipeline
About MongoDB Query Beautifier
This MongoDB query beautifier turns dense, one-line MongoDB shell queries into readable, properly indented code. Paste a cramped db.collection.find() call, a bare filter object, or a chained statement with sort, limit, and projection, and it pretty-prints the result with consistent spacing and clean line breaks. It is built for backend developers, database engineers, and QA testers who copy queries out of application logs, Compass, or chat threads and need to read, debug, or share them fast. The request is built and formatted entirely in your browser using Prettier, so there is no setup and no waiting on a server round-trip. Operators like $gte, $in, and $regex are preserved exactly as written, and the formatted output updates live as you paste or edit. When you are done, copy the result or download it as a .js file.
Features
- Beautifies db.collection.find() and other chained shell statements
- Indents bare filter objects and arrays, not just full queries
- Preserves operators like $gte, $in, $regex and $or exactly as written
- Keeps chained methods such as sort(), limit() and projection readable
- Pretty-prints with Prettier for consistent spacing and quoting
- Formats live as you type or paste — no Run button needed
- Copy the beautified query or download it as query.js
- Runs entirely in your browser with nothing uploaded
How to use the MongoDB Query Beautifier
- Paste your MongoDB query or find() statement into the input box.
- Read the beautified, indented query in the output panel as it updates live.
- Fix any reported syntax error, such as an unbalanced bracket.
- Copy the result or use Download to save it as query.js.
Example
Input
db.users.find({status:"active",age:{$gte:18}},{name:1,_id:0}).sort({createdAt:-1}).limit(20)
Output
db.users
.find({ status: "active", age: { $gte: 18 } }, { name: 1, _id: 0 })
.sort({ createdAt: -1 })
.limit(20);
A cramped find() call is indented into readable shell code.
Common errors & troubleshooting
- Could not format — unbalanced brackets or parentheses. — Check that every {, [ and ( has a matching close; paste the full statement, not a truncated snippet.
- A trailing comma or missing comma breaks parsing. — Remove the stray comma or add the missing one between fields, then the query reformats automatically.
- Pasting an aggregation pipeline instead of a query. — Use the MongoDB Aggregation Beautifier for db.collection.aggregate([...]) pipelines.
- Unquoted keys with special characters fail to format. — Wrap keys that contain dots or hyphens in double quotes, e.g. "address.city".
Frequently asked questions
- What is a MongoDB query beautifier?
- It is a tool that takes a compact, hard-to-read MongoDB shell query and reformats it with proper indentation, spacing, and line breaks so you can read and debug it. This one handles db.collection.find() calls, filter objects, and chained methods like sort and limit.
- Does it change what my query does?
- No. It only changes whitespace, indentation, and quoting style. The fields, operators, and values stay exactly the same, so the beautified query behaves identically to the original.
- Can it beautify aggregation pipelines too?
- This tool is tuned for find() queries and filter objects. For db.collection.aggregate([...]) pipelines with stages like $match and $group, use the MongoDB Aggregation Beautifier.
- Is my query data private and safe to paste here?
- Yes. The beautifier runs entirely in your browser using Prettier. The queries you paste never leave your device and nothing is uploaded to ArrayKit, so it is safe to format queries that contain sensitive field names or values.
- What indentation does it use?
- Output is indented with 2 spaces and consistent operator spacing for clean, predictable formatting that is easy to read and diff.
- Why does it say it could not format my query?
- That usually means the input has a syntax problem, such as an unbalanced bracket, a stray comma, or a truncated copy. Paste the complete statement and fix any mismatched brackets, and it will reformat automatically.
Related tools
All ArrayKit tools