What this tool formats
This tool pretty-prints MongoDB queries and pipelines into readable, indented JSON. It accepts two input shapes: plain JSON (a filter or aggregation array on its own), or MongoDB shell syntax like db.users.find({...}, {...}) — in which case it detects the db.collection.method(...) wrapper, extracts and re-indents each argument individually, and reassembles them inside the original method call.
It does not evaluate or connect to a database — this is purely a text formatter. It also doesn't currently support special BSON syntax that isn't valid JSON on its own, like unquoted ObjectId(...) or ISODate(...) constructors used in the mongo shell; wrap those in quotes as strings if you hit a parse error.
When to use it
Use it when debugging a complex aggregation pipeline copied from application logs, a slow-query log, or a colleague's Slack message as a single unreadable line — reformatting it makes nested $match, $group, and $lookup stages visible so you can actually trace the logic. It's also useful when writing documentation or code review comments: paste a compact query and get a clean, indented version to include in a PR description or runbook.
Because it detects the db.collection.method(...) wrapper automatically, you can paste queries copied directly from mongosh or Compass without manually stripping the wrapper first — just paste the whole line as-is.
Example
Input db.orders.find({"status":"shipped","total":{"$gt":100}},{"_id":0,"total":1}) reformats to db.orders.find(\n{\n "status": "shipped",\n "total": {\n "$gt": 100\n }\n},\n{\n "_id": 0,\n "total": 1\n}\n) — both the filter and projection arguments are independently pretty-printed and reassembled inside the original find(...) call.
How to use the MongoDB Query Formatter tool
- 1
Paste your query
Either raw JSON or full shell syntax like db.collection.find({...}) — the tool detects which one you pasted.
- 2
Click Format
Each argument is parsed and re-indented independently, then reassembled inside the original method wrapper.
- 3
Fix any parse errors
The error message shows what failed to parse — usually unquoted BSON constructors like ObjectId(...) need to become plain strings first.
- 4
Copy the result
Copy the formatted query to paste into documentation, a PR, or a debugging session.
Frequently asked questions
Does this run or validate the query against a real database?
No — it's a pure text formatter with no database connection. It reformats the query's structure but doesn't check whether the query is semantically valid or would actually execute correctly.
Why does it fail on ObjectId("...") or ISODate("...")?
Those are mongo-shell-specific constructor syntax, not valid JSON. The parser expects strict JSON, so wrap the value in quotes as a plain string (e.g. "64f1a2b3c4d5e6f7a8b9c0d1") to format successfully, then convert it back to the constructor form manually afterward if needed.
Does it support the full aggregation pipeline syntax?
Yes for any pipeline expressed as valid JSON — an array of stage objects passed to .aggregate([...]) is parsed and reformatted the same way as .find() arguments.
Is my query uploaded anywhere?
No. Formatting runs entirely in your browser using JavaScript's built-in JSON parser — nothing is sent to a server, which matters since queries often contain internal field names or production data shapes.
Related on TechLogHub
Related Formatter Tools
Get the next tool before you need it
One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.

