Boneyard Tools

MongoDB Query Builder

Add conditions with a field, operator and value to build a MongoDB filter. The tool shows the filter as JSON and a runnable db.collection.find() string with optional projection, sort and limit.

How to build a MongoDB query

  1. Type your collection name, such as users.
  2. Add condition rows: choose a field, an operator like gt or in, and a value.
  3. Set an optional projection, sort and limit, then copy the filter or the find() query.

Examples

Find users older than 21, newest first

collection: users, age gt 21, sort age desc, limit 10
db.users.find({"age":{"$gt":21}}).sort({"age":-1}).limit(10)

Match a role in a set

collection: users, role in admin,editor
db.users.find({"role":{"$in":["admin","editor"]}})

Frequently asked questions

Which operators are supported?

Equality and inequality (eq, ne), comparisons (gt, gte, lt, lte), set membership (in, nin), pattern matching (regex) and field presence (exists). The eq operator collapses to a bare value, the rest map to $gt, $in, $regex and so on.

How do I write an $in list?

Use the in or nin operator and type comma-separated values, for example admin, editor. The tool splits them into an array and converts numbers and booleans automatically.

Can I add a projection, sort and limit?

Yes. Projection fields become a {field: 1} include object as the second find() argument, sort becomes .sort({field: 1 or -1}), and limit becomes .limit(n). Each part is only added when you fill it in.

What happens with two conditions on the same field?

Comparison operators on one field merge into a single object, so gte 18 and lt 65 on age become {age: {$gte: 18, $lt: 65}}, which is how you write a range query in MongoDB.

Are values treated as numbers or strings?

A value that looks like a number, true, false or null is converted to that type; anything else stays a string. This keeps the generated filter matching the JSON you would write by hand.

Is my query sent to a server or run against a database?

No. The builder only generates text. Everything runs in your browser, nothing is uploaded, and the tool never connects to any database.

Related tools