MongoDB Query Builder (find, filter, sort, projection)
Write a MongoDB filter from readable lines and get both the find call and the equivalent aggregation.
Use the tool
Why this tool exists
Conditions are written as "field operator value" with =, !=, >, >=, <, <=, in, nin, regex and exists. Values are parsed as JSON where possible. The tool merges operators on the same field, adds a projection and sort and prints the find command, the equivalent aggregate pipeline and the filter as JSON.
When user input goes into a filter object, check its type: an attacker can send {"$ne": ""} where a string is expected (operator injection).
No data is sent anywhere: the work happens in your browser, so you can use it offline once the page has loaded.
How to use it
- Choose the collection.
- Write conditions, one per line.
- Set projection, sort and limit.
- Copy the mongosh command.
Frequently asked questions
What is operator injection?
Passing an object with $-operators in place of a value to change the query logic. Validate that values are plain strings or numbers.
Can it write updates?
No, only read queries.
Does it connect to a database?
No; it only writes the command.
Is my data sent anywhere?
No. Everything is processed in your browser, and the page makes no network requests with your input.