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
    • Reports
    • Case Studies
    • Whitepapers
    • Blog
    • Testimonials
    • Community
  • Contact us
    • Contact
    • Sales Support
    • Feedback and Support
    • Career
    • About Us
  • Store
    • Buy Now
    • Preferred Resellers
    • Team Pricing
  • My License
  • Download
search

Academy 3T

  • MongoDB 101: Getting Started
  • MongoDB 201: Querying MongoDB Data
  • MongoDB 301: Aggregation

Lesson 7, Exercise 2: Using IntelliShell’s auto-completion features to write queries

MongoDB 101: Getting Started Running MongoDB Queries on the mongo Shell Lesson 7, Exercise 2: Using IntelliShell’s auto-completion features to write queries

In this exercise, you will build two queries in IntelliShell. The first query changes the current database to BioData.  The second query retrieves document data from the bios collection. To create the second query, you will use IntelliShell’s built-in auto-completion features.

The queries in this exercise are very basic and are meant only to demonstrate how to use IntelliShell to build queries. In later courses, you’ll learn how to build more complex queries by taking advantage of other Studio 3T features.

To create the queries

1. Return to the IntelliShell tab, position your cursor at the end of the command you just ran, and press Enter to add a second line in the Editor.

2. On the new line, type the following command:

use BioData;

The command changes the current database context to BioData.

Ensure that your cursor is positioned to the right of the second command (on the same line) and click the Run statement at cursor button (execute at cursor).

You should receive a message stating that IntelliShell has switched to the BioData database.

intellishell authenticated true

3. Press Enter to add a third line to the Editor and type the following command:

db.

4. When you press the period, IntelliShell displays an auto-completion pop-up, as shown in the following figure.

autocompletion

If you don’t see auto-suggestions, double-check that you’ve clicked on the lightning bolt icon (Auto-completion icon) which triggers auto-completion.

The pop-up lists the collections and methods available to the current database object, as it’s accessed through the db variable. You can scroll to any item and then press Enter to add it to your command in the Editor.

5. In the pop-up, ensure that the bios collection is selected and then press Enter. The collection is added to the command.

6. In the Editor, type a period after db.bios. 

This will again launch the auto-completion pop-up, which lists the methods available to the bios collection object.

7. In the pop-up, scroll down to the find method.

A message box will appear to the right, displaying information about the method.

Find method criteria in IntelliShell

The description explains how to use the find method and provides examples of its use.

As you can see, the method returns documents in a collection. If no arguments are specified, the method returns all documents.

8. Press Enter to add the find method to the command.

When you add a method, IntelliShell also adds a set of parentheses, where you can insert arguments if needed. For this exercise, you will add one argument.

9. Within the parenthesis, type the following code as an argument, including the curly braces:

{contribs:"ALGOL"}

The argument defines a filter based on a specific field and value pair. As a result, only documents that contain the ALGOL value in the contribs field will be returned. At this point, your command should look similar to the following code:

db.bios.find({contribs:"ALGOL"})

10. At the end of the command, after the closing parentheses, type a period, followed by the letter p, as in .p.

This launches the auto-completion pop-up, displaying a list of methods that contain the letter p.

You can filter the list of available methods by typing one or more letters. For example, if you type .ad after the find method, the pop-up will display only methods that contain these letters, such as addOption and readConcern. You can then select a method from the filtered list.

From the pop-up, select the pretty method and press Enter.

The pretty method displays the results in a more readable format

The pretty method displays the results in a more readable format. Your command should now look similar to the following code: 

db.bios.find({contribs:"ALGOL"}).pretty();

Notice the semicolon terminator has been added to the end of the command. It tells MongoDB that the command ends at this point.

In this situation, in which a single command appears on a single line, the semicolon is not necessary, but it can be useful when running multiple commands to clearly distinguish the end of each command, especially if those commands span multiple lines. Some developers like to include the semicolon for all commands as part of their best practices.

Do not do anything else with your query at this time. You will use it for the next exercise.

Terms you might not know:

argument: In programming, a value that is passed between programs, subroutines or functions. Arguments are independent items, or variables, that contain data or codes (source)

Next – Lesson 7, Exercise 3: Running queries in IntelliShell and viewing the results
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
    2 Topics
    Lesson 2, Exercise 1: Setting up MongoDB Atlas
    Lesson 2, Exercise 2: Configuring 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
    • Case Studies
    • White Papers
    • Testimonials
    • Discounts

    Company

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

    © 2022 3T Software Labs GmbH. All rights reserved.

    • Privacy Policy
    • Cookie settings
    • Impressum
    When you click "Accept", you are agreeing to cookies being on your device. They may improve site navigation, site usage analysis, or the relevance of messages. It is up to you which cookies are enabled. Read our Privacy Policy.
    Manage cookies
    Accept
    ✕

    Privacy Preference Center

    A cookie is a small file of letters and numbers that is downloaded on to your computer when you visit a website. Cookies are used by many websites and can do a number of things, eg remembering your preferences, recording what you have put in your shopping basket, and counting the number of people looking at a website. In the form below you can choose which cookies, except for essential cookies, to allow or disable.

    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.

    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.

    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