Skip to content
Studio 3T - The professional GUI, IDE and client for MongoDB
  • Tools
    • Aggregation Editor
    • IntelliShell
    • Visual Query Builder
    • Export Wizard
    • Import Wizard
    • Query Code
    • SQL Query
    • Connect
    • Schema Explorer
    • Compare
    • SQL ⇔ MongoDB Migration
    • Data Masking
    • Task Scheduler
    • Reschema
    • More Tools and Features
  • Solutions
  • Resources
    • Knowledge Base
    • MongoDB Tutorials & Courses
    • Tool/Feature Documentation
    • Blog
    • Community
    • Testimonials
    • Whitepapers
    • Reports
  • Contact us
    • Contact
    • Sales Support
    • Feedback and Support
    • Careers
    • About Us
  • Store
    • Buy Now
    • Preferred Resellers
    • Team Pricing
  • Download
  • My 3T
search

Studio 3T Knowledge Base

  • Documentation
  • Tutorials
  • Workshops
Take the fastest route to learning MongoDB. Cover the basics in two hours with MongoDB 101, no registration required.
Start the free course

Visual Query Builder

Posted on: 19/11/2018 (last updated: 09/03/2022) by Dakota Karlsson
tl;dr
Shortcuts

Visual Query Builder lets you 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. Try it today.

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)

Visual Query Builder is just one of four ways to query MongoDB in Studio 3T.

Basics

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

Download Studio 3T in case you haven’t yet to start using Visual Query Builder.

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

The Collections Tab houses the Visual Query Builder in Studio 3T.

The Collection Tab houses both the Visual Query Builder:

The Visual Query Builder has 3 sections: Query, Projection, and Sort. Use drag-and-drop documents to start building a MongoDB query.

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

The Main Query Bar will reflect the query being built in the Visual Query Builder. You can also edit your query via here as well.

There are three ways to open the Visual Query Builder:

  • Button – Click on the Visual Query Builder button
The simplest way to open the Visual Query Builder is to click the 'Visual Query Builder'.
  • Right-click – Right-click anywhere in the Result tab and choose Query Builder [/ht_toggle]
  • Shortcut – 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.

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:

db.Customers.find(
{
"title" : "Ms",
"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.

Build your query in the in Query section, decide what fields to show in the Projection section, and choose how the results are sorted in the Sort section.

Query section

State the operators as needed under the Query Section.

The MongoDB operators available.

See the full list of MongoDB Query and Projection operators here.

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.

Supported BSON value types in Studio 3T.

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.

The Projection section in Studio 3T. Use this to specify how results are presented.

Sort section

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

It’s important to note that the Sort section can only define one field at a time.

Choose how results are sorted and in what order via the Sort section.

Read more about how MongoDB can sort data.

Clone field rules

With Release 2018.5.1, you can now also clone field rules in one click – a nifty feature that spares you the repetitive drag-and-drop, especially when you’re dealing with very similar field rules.

Query MongoDB arrays

It is also possible to match on array elements using the Visual Query Builder, either as a standalone query or as part of an AND/OR group.

We highly recommend Table View when querying array elements, so that you can easily step into and out of array-valued columns.

Standalone query

To directly find array elements that match a query criteria:

  1. Within the Query Section, choose Has array element(s) matching from the dropdown.
Choose Has array elements matching from the dropdown

2. This will trigger the Array dropdown to appear. Choose the array you want to query. We will look at the array cities_visited, which contains two elements at most (see column).

Choose the array you want to query from the dropdown

3. Step into the array-valued column you want to query.

4. Double-click in the Query Section to choose the default option <Array Element>.

This might seem unnatural to veterans of VQB’s dragging function. Dragging array elements will cause Studio 3T to automatically take the JSON path (e.g. cities_visited_0). For the query to work, you need to set the field to the default option <Array Element>.

5. Define your operator (e.g. equals, contains).

6. Drag or type in the value to be matched on (in this example, Berlin).

7. Drag or type in the value to be matched on (in this example, Berlin).

Find array elements as part of an AND/OR group

Querying in an AND/OR group follows the same steps as a standalone query.

The only difference is, you must first state the desired operator at the top of the Query Section.

  1. Select one of the following operators:- Match all of ($and)
    • Match any of ($or)
    • Match none of ($nor)In this case, there’s take the $or operator.

2. Click on Add AND/OR group.

Click on Add AND/OR group

3. From here, follow steps 1-6 of querying array elements in a standalone query.

4. Create more AND/OR groups as needed.

AND/OR MongoDB array elements

5. Run the query.

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.

View your query in the mongo Shell language via the Main Query Bar.

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 the query you;ve built in teh Visual Query Builder.
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, PHP 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
Translate your query from the mongo Shell language into: JavaScript, Java, C#, Python, and PHP.

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 Wizard + Export Wizard – Import/export in various formats, without writing a single command

How helpful was this article?
This article was hideous
This article was bad
This article was ok
This article was good
This article was great
Thank you for your feedback!

About The Author

Dakota Karlsson

New to the world of databases, Dakota hails from a rural town in Texas and is learning just how exciting databases can be. After brief stops in the Big Sky state and a few years in Scandinavia, he now calls Berlin home and spends his spare time involved in the Berlin music scene and experiencing the art of German cuisine.

Article navigation

Related articles

  • Lesson 4, Exercise 2: Using Visual Query Builder to query a single array value
  • Lesson 4, Exercise 3: Using Visual Query Builder to query multiple array values
  • Lesson 5, Exercise 3: Using Visual Query Builder to query embedded documents
  • What’s New in Studio 3T 2021.9 | Popup Visual Query Builder and Aggregation Index Hints
  • Lesson 2, Exercise 2: Using Visual Query Builder to build and run find statements

Studio 3T

MongoDB Enterprise Certified Technology PartnerSince 2014, 3T has been helping thousands of MongoDB developers and administrators with their everyday jobs by providing the finest MongoDB tools on the market. We guarantee the best compatibility with current and legacy releases of MongoDB, continue to deliver new features with every new software release, and provide high quality support.

Find us on FacebookFind us on TwitterFind us on YouTubeFind us on LinkedIn

Education

  • Free MongoDB Tutorials
  • Connect to MongoDB
  • Connect to MongoDB Atlas
  • Import Data to MongoDB
  • Export MongoDB Data
  • Build Aggregation Queries
  • Query MongoDB with SQL
  • Migrate from SQL to MongoDB

Resources

  • Feedback and Support
  • Sales Support
  • Knowledge Base
  • FAQ
  • Reports
  • White Papers
  • Testimonials
  • Discounts

Company

  • About Us
  • Blog
  • Careers
  • Legal
  • Press
  • Privacy Policy
  • EULA

© 2023 3T Software Labs Ltd. All rights reserved.

  • Privacy Policy
  • Cookie settings
  • Impressum

We value your privacy

With your consent, we and third-party providers use cookies and similar technologies on our website to analyse your use of our site for market research or advertising purposes ("analytics and marketing") and to provide you with additional functions (“functional”). This may result in the creation of pseudonymous usage profiles and the transfer of personal data to third countries, including the USA, which may have no adequate level of protection for the processing of personal data.

By clicking “Accept all”, you consent to the storage of cookies and the processing of personal data for these purposes, including any transfers to third countries. By clicking on “Decline all”, you do not give your consent and we will only store cookies that are necessary for our website. You can customize the cookies we store on your device or change your selection at any time - thus also revoking your consent with effect for the future - under “Manage Cookies”, or “Cookie Settings” at the bottom of the page. You can find further information in our Privacy Policy.
Accept all
Decline all
Manage cookies
✕

Privacy Preference Center

With your consent, we and third-party providers use cookies and similar technologies on our website to analyse your use of our site for market research or advertising purposes ("analytics and marketing") and to provide you with additional functions (“functional”). This may result in the creation of pseudonymous usage profiles and the transfer of personal data to third countries, including the USA, which may have no adequate level of protection for the processing of personal data. Please choose for which purposes you wish to give us your consent and store your preferences by clicking on “Accept selected”. You can find further information in our Privacy Policy.

Accept all cookies

Manage consent preferences

Essential cookies are strictly necessary to provide an online service such as our website or a service on our website which you have requested. The website or service will not work without them.

Performance cookies allow us to collect information such as number of visits and sources of traffic. This information is used in aggregate form to help us understand how our websites are being used, allowing us to improve both our website’s performance and your experience.

Google Analytics

Google Ads

Bing Ads

Facebook

LinkedIn

Quora

Hotjar

Functional cookies collect information about your preferences and choices and make using the website a lot easier and more relevant. Without these cookies, some of the site functionality may not work as intended.

HubSpot

Social media cookies are cookies used to share user behaviour information with a third-party social media platform. They may consequently effect how social media sites present you with information in the future.

Accept selected