Visual Query Builder helps you build MongoDB queries by dragging and dropping fields from the documents in a collection, perfect for when you’re learning the MongoDB query syntax or if you don’t know it at all. To try Studio 3T’s MongoDB query builder, download it today!
Open Visual Query Builder – Ctrl + B (⌘+ B)
Run Query – Ctrl + R (⌘+ R)
Switch to Tree View – Ctrl + Alt + 1 (⌥ + ⌘ + 1)
Switch to Table View – Ctrl + Alt + 2 (⌥ + ⌘ + 2)
Switch to JSON View – Ctrl + Alt + 3 (⌥ + ⌘ + 3)
Visual Query Builder is part of the Collection Tab, where you can view, query, and edit documents in a collection. You can drag and drop fields into Visual Query Builder to create a MongoDB query, and as you do this, you’ll see Studio 3T building the mongo shell syntax in the Query Bar.
To open Visual Query Builder:
- Button – Click on the Visual Query Builder button
- Right-click – Right-click anywhere in the Result tab and choose Visual Query Builder
- Shortcut – Press Ctrl + B (⌘+ B)
- Click-and-drag – Click and drag any cell in the Result tab and Visual Query Builder automatically opens
Select the target field by clicking on any cell (not the header), then drag the selected field(s) and drop them into Visual Query Builder.
In Table View, you can select only one field at a time.
In Tree View, you can select multiple fields and drop them into Visual Query Builder. To do this, hold the CTRL key (or the command key) and click the fields.
As you build your MongoDB query, you’ll see Studio 3T writing the mongo shell syntax in the Query Bar.
To filter and sort the documents in the collection, define the required operators and values.
Select the operators in the Query section.
By default, Visual Query Builder uses the
$and operator, Match all of ($and) to combine multiple conditions where all the conditions must be satisfied for a match.
Select Match any of ($or) to use the
$or operator to combine multiple conditions where any of the conditions can be true for a match.
Visual Query Builder automatically detects the value type, for example Int32, String, or RegEx from the fields that you drag and drop. You can change the data type by clicking on the type button.
For string values, you can open a multiline text editor for editing long strings by clicking the ellipsis button.
Advanced editors are also available for binary, reference, and regex values.
You can clone field rules using the duplicate button, for example when you need to specify fields with similar conditions.
The Projection section allows you to include or exclude specific fields from the query results.
The Sort section allows you to sort query results by a specific field, in either ascending or descending order.
You can match on array elements using Visual Query Builder, either as a standalone query or as part of an AND/OR group.
To directly find array elements that match query criteria:
- In the Query section, choose Has array element(s) matching from the dropdown.
2. In the Array list, choose the array you want to query. We’ll look at the array cities_visited.
3. Step into the array-valued column you want to query.
4. Double-click in the box to select the default option
5. Select your operator (in this example, equals).
6. Type in the value to be matched on (in this example, Berlin).
1. Select one of the following operators:
- Match all of ($and)
- Match any of ($or)
- Match none of ($nor)
In this case, let’s use the
2. Click on Add AND/OR group.
3. From here, follow the steps in querying array elements in a standalone query.
4. Create more AND/OR groups as needed.
5. Run the query.
When you have the required fields, operators, and values in place, click the Run button (play symbol) at the top of the Collection tab or the Run button in the Visual Query Builder.
Click on the Query Code tab to view the query in mongo shell language. MongoDB uses the
find() method to retrieve documents from a collection.
To generate query code in other languages:
- Run the query
- Click on the Query Code tab
- Choose the target language