Skip to content

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.

The MongoDB visual query builder: sampled fields of the products collection on the left, a filter on category and price.amount, a descending sort, and the generated find() text below, with the matching products in a table.The MongoDB visual query builder: sampled fields of the products collection on the left, a filter on category and price.amount, a descending sort, and the generated find() text below, with the matching products in a table.
Build a query from the sampled fields; the find() text follows every change.

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.
  1. Drag a field onto Filter, or open the field’s + menu (Add field to…) and choose Add to filter.
  2. Pick an operator for the condition.
  3. Enter the value. The value type starts as the field’s type; change it if you need another.
  4. 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.

  • 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 _id may 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.

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.

Documents Querybara 0.1.19 · built from89dc752