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.
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 ().
You should receive a message stating that IntelliShell has switched to the
4. When you press the period, IntelliShell displays an auto-completion pop-up, as shown in the following figure.
If you don’t see auto-suggestions, double-check that you’ve clicked on the lightning bolt 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.
bioscollection is selected and then press Enter. The collection is added to the command.
This will again launch the auto-completion pop-up, which lists the methods available to the
bios collection object.
A message box will appear to the right, displaying information about the method.
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.
findmethod 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.
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:
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
readConcern. You can then select a method from the filtered list.
From the pop-up, select the
pretty method and press Enter.
pretty method displays the results in a more readable format. Your command should now look similar to the following code:
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.