Visual query builder
- MongoDB
The visual query builder docks at the right of the collection tab.
It lists the collection’s fields from a sample and lets you drop them into a filter, a projection
and a sort. Each condition is typed after the field. The query bar’s fields and its find() text
follow every change, and the builder follows them when you edit them.


Open the builder
Section titled “Open the builder”In the collection tab, choose Visual Query Builder at the right end of the toolbar, or run
MongoDB: Toggle Visual Query Builder from the command palette. The builder opens at the right of
the tab, beside the query bar. The first time, Querybara samples 1,000 documents of the collection
and lists their fields at the top of the builder with their BSON types, for example String,
Int32, Date or String[] for an array of strings.
- Find a field or type a path filters the list. A path that is not in the sample can be typed here and added too.
- Sample the fields again reads a new sample.
Build a filter
Section titled “Build a filter”- Drag a field onto Filter, or open the field’s + menu (Add field to…) and choose Add to filter.
- Pick an operator for the condition.
- Enter the value. The value type starts as the field’s type; change it if you need another.
- Press Enter in the value, or choose Run at the top of the builder.
Conditions in Filter must all match (AND). To match any of several conditions, choose Add to a new OR group from a field’s menu; later fields can go into that group with Add to OR group 1, or by dropping them on it. OR groups go one level deep.
| Operator | Value |
|---|---|
| equals ($eq) | One value |
| not equal ($ne) | One value |
| greater than ($gt) | One value |
| at least ($gte) | One value |
| less than ($lt) | One value |
| at most ($lte) | One value |
| one of ($in) | One value per line |
| none of ($nin) | One value per line |
| contains all ($all) | One value per line |
| matches ($regex) | A pattern, and flags i, m, s, u or x |
| array size ($size) | A number of elements |
| exists ($exists) | Whether the field exists |
| has type ($type) | A BSON type |
| is null | Nothing |
The value types are String, Int32, Int64, Double, Decimal128, ObjectId,
Date, Boolean, UUID and mongosh (any mongosh expression, such as { a: 1 }).
A value that does not fit its type is marked on the condition, for example “Enter an ISO date”. It
is left out of the find() text, which says so (“Not in the find() text yet”), and Run stops
with “Fix the query first” until you correct it.
Projection and sort
Section titled “Projection and sort”- Add to projection puts a field into Projection, where you set it to Include or
Exclude. MongoDB’s rule applies: a projection either includes or excludes fields, and only
_idmay differ. The builder explains when the rule is broken. - Add to sort puts a field into Sort, set to Asc or Desc. Keys sort by the first, then the next. Reorder them by dragging, with Alt + ↑ and Alt + ↓ on a key’s handle, or with the move buttons.
- Skip and Limit sit under the zones.
Edit the query bar
Section titled “Edit the query bar”The query bar stays beside the builder, and its fields and find() text can be edited:
db.orders.find({ status: 'open', total: { $gt: 100 } }, { total: 1, _id: 0 }).sort({ total: -1 }).limit(3)When you change them, the builder reads the query back. If the query uses something the builder cannot show,
such as $elemMatch, the builder says “This query can’t be shown in the builder” with the reason
and stays read-only. The text still runs. Once the query is simple again, the builder follows it.
Choose Visual Query Builder again, or the close button at the top of the builder, to close it. The query stays in the query bar.
Related
Section titled “Related”Documents Querybara 0.1.19 · built from89dc752