Introducing IntelliShell

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.

IntelliShell feature

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 Search Query History dialog box, where you can view the past queries you’ve executed as well as copy them into the Editor. You can also clear the query history.
  • 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 Shell Output tab, which is used for all queries when the Raw shell mode option is selected 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).

Open a scriptFolder iconOpens a script file in the Editor, where you can then edit and run the commands, either individually or grouped together.
Save the current scriptsave iconSaves the current set of commands to a script file.
Execute entire scriptExecute entire scriptRuns all commands currently typed into the Editor.
Execute statement at cursorScript at cursorRuns the command where the cursor is positioned. The command can span multiple lines.
Execute selectionExecute selectionRuns all selected commands. The option is grayed out if no text is selected.
Clear the result tabsClear result tabCloses all open result tabs.
Retain previous result tabsRetain previous tabInstructs IntelliShell to open a result tab for each executed command, rather than overwriting the existing results.
Raw shell moderaw shell modeInstructs IntelliShell to return all results to the Shell Output tab, regardless of the query type.
Show Visual Query Builder Launches the Visual Query Builder.
Shell Methods Reference Opens a webpage on the MongoDB website, where you can access information about the various methods available to the mongo shell.

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");
   _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"],
       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.

Log in

Log in to your Studio 3T Academy account

Forgot password?

Don't have an account yet? Sign up
Sign up

Start learning MongoDB today. All fields are mandatory.

By signing up for a course, you agree to the 3T Software Labs Privacy Policy.

Already have an account? Log in