Visual Query Builder

Visual Query Builder lets users build queries visually by dragging and dropping fields, a feature perfect for those who do not know or are still learning the MongoDB query syntax.

Open Visual Query Builder - Ctrl + F (⌘+ F)
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)


The Visual Query Builder allows for the creation of MongoDB queries via drag-and-drop, in combination with the Table and Tree Views.


Studio 3T’s drag-and-drop MongoDB query builder is part of the greater Collections Tab, which is where users can view, query, and edit documents within the collection.

The Collections Tab houses both the Visual Query Builder:

And the Main Query Bar, which shows the mongo shell’s syntax as it is being built:

The Main Query Bar.

There are three ways to open the Visual Query Builder:


Click the Query Builder button

The Visual Query Button.


Right-click anywhere in the Result tab and choose Query Builder


Press Ctrl + F (⌘+ F)

Prefer the mongo shell? Autocomplete queries with IntellIShell instead.

Build the MongoDB query

Let’s build a query using Studio 3T’s MongoDB query builder and the Customers replica data set, which can be downloaded here.

Drag and drop fields

Select the target field by clicking on any cell (not the header), then drag the selected field(s) and drop them into the Query Builder.

In Table View, fields can only be selected one at a time.

In Tree View, multiple lines can be selected and dropped into the Visual Query Builder simultaneously. To do this, hold ‘ctrl‘ and click the fields to be used.

Drag and drop multiple documents with Tree View.

Customize the query

To better specify the query, drag as many fields as necessary.

Here is the query built using the Visual Query Builder from the above GIF, in MongoDB query syntax:

"title" : "Mr",
"package" : "XL",
"transactions" : {
"$gt" : NumberInt(46)

Define values and operators

To further filter queries, define the desired operators and values in the Query, Projection, and Sort sections.

The sections in the Visual Query Builder

Query section

State the operators as needed under the Query Section.

The MongoDB operators available.

By default, the $and operator is automatically used to combine queries.

The $or operator is NOT selected by default and must be manually added. To ensure functionality, state the $or operator before defining the fields as seen in the example below.


The Visual Query Builder will automatically detect value type (e.g. Int32, string, regex) from added fields. Switch between field types by clicking on the Value icon.

BSON types.

For string values, a multiline text editor – handy for editing long strings – can be opened by clicking on the ellipsis icon.

Similar advanced editors can also be found for regex, undefined, and binary values.

Multi-line Text Editor.

Click here for the complete list of MongoDB-supported BSON types.

Projection section

The Projection section allows users to include or exclude specific fields from the query results.

VQB Projection Pane.

Sort section

The Sort section lets users sort query results by a specific field, in either ascending or descending order.

If multiple fields are defined (say, last name – ascending and first name – descending), Visual Query Builder will sort the results by the first field (last name). The second field (first name) won’t be considered.

VQB Sorting Pane.

Read more about how MongoDB can sort data.

View the built query in the mongo shell language

The Visual Query Builder simultaneously displays the built query in mongo shell syntax under the Main Query Bar, which also shows the changes made to it as it’s being built.

Main Query Bar.

The original query has now been extended as follows:

Original query

"title" : "Mr",
"package" : "XL",
"transactions" : {
"$gt" : NumberInt(46)

Final query

"title" : "Mr",
"package" : "XL",
"transactions" : {
"$gt" : NumberInt(46)
"title" : 1.0,
"first" : 1.0,
"last" : 1.0,
"package" : 1.0,
"transactions" : 1.0
"last" : 1.0

The Query Code tab also shows the built query in JSON and four other languages.

Run the MongoDB query

Once the correct fields, values, and operators are in place, click the Execute button (play symbol) at the top of the screen or the Run button towards the bottom of the screen.

Run Query symbols.

Order documents by creation date

To display the newest documents first, sort the MongoDB collection by the field _id in descending order, or in ascending order to show oldest documents first.

Generate JavaScript, Java, Python and C# code from built queries

In addition to showing the built query in its full mongo shell syntax, Query Code also translates built queries into JavaScript (Node.js), Java (2.x and 3.x driver API), Python and C#.

To see a built query’s equivalent code:

  1. Execute the query
  2. Click on the Query Code tab
  3. Choose the target language

New to MongoDB? Be productive from day one with these helpful features:

  • SQL Query – Use SQL to query MongoDB and see how it translates to the MongoDB query language
  • Aggregation Editor – Write MongoDB aggregation queries in stages
  • Import/Export Wizard – Import/export in various formats, without writing a single command

Updated on September 27, 2018

Was this article helpful?

Related Articles