IntelliShell offers the simplicity of the mongo shell, but adds an assortment of features to make it easier to query a database and view the results.
You can launch IntelliShell from the Studio 3T menu or through the Connection Tree. For example, you can launch IntelliShell from a database or collection node.
IntelliShell opens as a separate tab, which is divided into two sections.
The top section provides tools and a window (the Editor) for building and running commands against a MongoDB database.
The bottom section is a separate window that displays one or more result tabs. The number and name of the tabs will depend on how you configure the IntelliShell options and the type of queries you run.
The following figure shows the IntelliShell tab, with the main components outlined.
The components on the IntelliShell tab can be broken down as follows:
- Current database: Shows the currently active database, which you can change by running a
use
statement. When you change the database context, IntelliShell automatically updates the database name on the top label. - Query History: Launches the IntelliShell Script Manager dialog box, where you can view the past queries you’ve executed, copy them into the Editor, or clear the query history. You can also view your bookmarks by clicking on the Bookmarks tab.
- Bookmark Manager: Clicking on the star icon prompts you to save a query or script as a bookmark. Clicking on the down arrow leads you to the Bookmark Manager where you can view previous bookmarks.
- Show editor and result tabs horizontally or vertically: Allows you to choose between a horizontal or vertical orientation of IntelliShell’s tabs.
- IntelliShell toolbar: A set of tools for running queries and viewing results. The individual tools are described in the table below.
- IntelliShell editor: The actual command-line interface where you type commands that can be executed against the current database. You can run individual commands or multiple commands together.
- Result tab: A tab that displays the results from executing one or more queries. Multiple result tabs can be open at the same time, with different names for the tabs. That tab name depends on the IntelliShell settings and the type of queries. For example, the above figure shows the Raw Shell Output tab, which is used for all queries when Query Assist is disabled on the toolbar.
The IntelliShell toolbar includes a set of tools for running queries and displaying their results. The following table describes the tools in the order they appear on the toolbar (from left to right).
Option | Icon | Description |
Add new script | Adds new script which also clears the editor. If there are unsaved changes to a current script, Studio 3T will prompt you to save them. | |
Open a script | Opens a script file in the Editor, where you can then edit and run the commands, either individually or grouped together. | |
Save the current script | Saves the current set of commands to a script file. | |
Run entire script | Runs all commands currently typed into the Editor. | |
Run statement at cursor | Runs the command where the cursor is positioned. The command can span multiple lines. | |
Run selection | Runs all selected commands. The option is grayed out if no text is selected. | |
Enable auto-completion | Enables or disables auto-suggestion of hints as you type. | |
Enable Query Assist | Runs the query on Studio 3T instead of the mongo shell. This is enabled by default. | |
Format code | Formats the code. | |
Shell Methods Reference | Opens a webpage on the MongoDB website, where you can access information about the various methods available to the mongo shell. | |
Show Visual Query Builder | Launches the Visual Query Builder. |
From the IntelliShell Editor, you can also load and run script files with a single command. In this way, you don’t have to retype the same commands each time you want to execute them. This is especially useful for testing applications or features that require you to set up a clean environment with each test cycle.
For example, the following commands are part of a simple script file that defines a variable, creates a database, and adds a collection to the database:
obj_id = ObjectId(); db = new Mongo().getDB("Authors"); db.getCollection("19th_century").insertMany([ { _id: obj_id, pen_name: { first: "Mary", last: "Shelley" }, }, { name: { first: "Mary", middle: "Wollstonecraft", last: "Shelley" }, pen_id: obj_id, tags: ["novelist", "dramatist", "biographer", "travel writer"], dates: { born: ISODate("1797-08-30"), married: ISODate("1814-07-28"), died: ISODate("1851-02-01") } }]);
When you access a database directly through the mongo shell, you can achieve the same results with the use
command, but this approach does not work when loading and running a script file. In this case, you must work with the database object, which you access through the db
variable.
Be careful when creating a script file and ensure that all elements will work as expected.
In most cases, running commands in a script file works the same as running them directly within the Editor, with a few notable exceptions, such as accessing the database object.