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

Academy 3T

  • Explore our courses
    • MongoDB 101: Getting Started
    • MongoDB 201: Querying MongoDB Data
    • MongoDB 301: Aggregation
  • Get certified

Lesson 4, Exercise 3: Using Visual Query Builder to query data

MongoDB 101: Getting Started The MongoDB Basics: Databases, Collections & Documents Lesson 4, Exercise 3: Using Visual Query Builder to query data

In this exercise, you will use Visual Query Builder to create a query that you will run against the welsh_pubs collection. The query limits the results to pubs that contain the term snooker in their name. The query also limits the number of fields included in the results.

To create the query

1. On the welsh_pubs collection tab, ensure that the collection data is displayed in Table View and click the Visual Query Builder link to open the query form.

2. In the Query section of the query form, click the Add icon (white-on-green plus sign) in the text box.

Visual query tab

The form will expand to include options for defining a search condition.

3. The first drop-down list in the expanded section includes the collection’s fields.

From the list, select the name field.

Query tab

4. The second drop-list list contains a list of operators for defining the search condition.

From the list, select the contains operator.

Query tab

5. In the text box beneath the two drop-down lists, type snooker.

Query snookers

6. Click the Run button at the top right corner of the Query section.

The Result tab is updated to include only pubs whose name includes snooker, which totals 17 documents, as shown in the following figure.

query result tab

You do not need to run the query at this time, but running the query as you build it can reduce the dataset to a more manageable size, while letting you periodically test your query.

7. On the Result tab, locate one of the Caerphilly values in the local_authority column and drag it to the second text box in the Query section of the query form (the text box that includes the text Drag field here or double-click).

8. In the operators drop-down list, select doesn’t equal.

Choose local_authority as field

This ensures that the final query results will not include any pubs that are governed by the Caerphilly local authority.

9. On the Result tab, change the display to Tree View and expand the address field in the first document.

Query caerphilary tree view

10. Select the following four fields: fsa_id, name, city – which we’ll refer to later as address.city because it is a nested field of address – and local_authority.

To select multiple fields in Windows, click the first field, press Control and click each of the additional fields. For macOS, click the first field, press Command and click each of the additional fields.

11. Drag the selected fields to the text box in the Projection section (the text box that includes the text Drag and drop fields here or double-click).

Projection tab

12. On the Result tab, de-select the four fields and then drag the address.city field to the text box in the Sort section (the text box with the text Drag and drop fields here or double-click).

The query form should now look like the following figure.

The query bar at the top of the welsh_pubs collection tab is updated as you build your query, so it should now reflect the Query, Projection, and Sort sections as they’re defined in Visual Query Builder.

13. On the Result tab, display the documents in Table View.

14. Then click the Run query (Execute entire script)button at the right side of the query bar.

The Result tab should now display only 14 rows and include only the _id, fsa_id, name, address, and local_authority fields.

15. On the query bar, click the Hide Query Builder link to close the query form.

16. Open Studio 3T preferences and select the Show all embedded fields in Table View check box on the General tab.

preference tab

When you select the check box, a message box appears, explaining how to apply your changes.

Click OK to close the message box, and then click OK to close the Preferences dialog box.

17. On the Result tab, right-click anywhere in the document area and click Restore Default View.

Restore default view

Studio 3T adds a column to the Result tab for the address.city field, making it easier to see all the data at a glance.

Show embedded fields

Leave the collection open for the next exercise.

Previous Topic
Back to Lesson
Next Topic
  • Course Home Expand All
    Introduction to MongoDB and Studio 3T
    1 Quiz
    Test your skills: Introduction to MongoDB and Studio 3T
    Introduction to MongoDB Atlas
    1 Topic
    Lesson 2, Exercise: Setting up MongoDB Atlas
    Connecting to MongoDB
    1 Topic | 1 Quiz
    Lesson 3, Exercise: Connecting to MongoDB via Studio 3T
    Test your skills: Connecting to MongoDB
    The MongoDB Basics: Databases, Collections & Documents
    7 Topics | 2 Quizzes
    Lesson 4: Understanding MongoDB Documents: Fields & Data Types
    Test your skills: Understanding MongoDB Documents
    Lesson 4: Comparing MongoDB vs SQL Concepts
    Lesson 4, Exercise 1: Creating a collection from a .json file
    Test your skills: Creating a Collection
    Lesson 4, Exercise 2: Reviewing the collection in different views
    Lesson 4, Exercise 3: Using Visual Query Builder to query data
    Lesson 4, Exercise 4: Updating data directly within the collection
    Post-Basics Course Feedback
    Using SQL in MongoDB Aggregation
    3 Topics | 1 Quiz
    Lesson 5, Exercise 1: Running a SQL aggregate query in MongoDB
    Test your skills: Using SQL in MongoDB Aggregation
    Lesson 5, Exercise 2: Exporting a SQL query to the Aggregation Editor
    Lesson 5, Exercise 3: Editing a query in the Aggregation Editor
    Importing and Exporting MongoDB Data
    3 Topics | 1 Quiz
    Lesson 6, Exercise 1: Importing document data from a .csv file
    Lesson 6, Exercise 2: Exporting document data to a .json file
    Lesson 6, Exercise 3: Exporting document data to a new collection
    Test your skills: Importing and Exporting MongoDB Data
    Running MongoDB Queries on the mongo Shell
    4 Topics | 1 Quiz
    Lesson 7: Introducing IntelliShell
    Lesson 7, Exercise 1: Using IntelliShell to load and run a script file
    Lesson 7, Exercise 2: Using IntelliShell’s auto-completion features to write queries
    Lesson 7, Exercise 3: Running queries in IntelliShell and viewing the results
    Test your skills: Running MongoDB Queries on the mongo Shell
    Course Extras
    Return to MongoDB 101: Getting Started
  • 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

    Reddit

    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