Try Studio 3T for Free

IntelliShell

IntelliShell is the built-in mongo shell in Studio 3T that offers live error highlighting and smart auto-completion of JavaScript standard library functions, shell-specific types and methods, operators, collection names, field names, and shell helper commands. Try it today.

Open IntelliShell – Ctrl + L (⌘+ L)
Trigger auto-completion – Ctrl + Space (^ + Space)
Find – Ctrl + F (⌘+ F)
Replace – Ctrl + H (Shift + ⌘ + F)
Comment with line comment – Ctrl + / (⌘+ /)
Open script – Ctrl + O (⌘+ O)
Save script – Ctrl + S (⌘+ S)
Save script as – Shift + Ctrl + S (Shift + ⌘+ S)
Execute entire script – F5
Execute statement at cursor – F6
Execute selection – F9

Prerequisites

Download Studio 3T and choose the right version for your particular platform and bit size.

IntelliShell requires the mongo shell executable, one of the mongo client tools bundled when downloading MongoDB.

No additional configuration is needed for Windows, macOS, or Linux installations. The mongo shell executable is bundled with Studio 3T on these systems.

If you want to use another version of MongoDB, here’s how you can point IntelliShell to use a different mongo.exe file.

Custom mongo shell

If you choose to use your own installation of the mongo shell, you can configure this in Studio 3T.

Once the mongo client tools are installed:

  1. Go to Studio 3T > Preferences.
  2. Click on the IntelliShell tab.
  3. Insert the path of where the mongo shell executable is located.
  4. Click OK.

IntelliShell is just one of four ways to query MongoDB in Studio 3T.

Launch IntelliShell

Choose a target server, database, or collection in the Connection Tree, then open IntelliShell through three ways:

IntelliShell icon in the toolbar

  • Button – Click on the IntelliShell button in the global toolbar
  • Right-click – Right-click and choose Open IntelliShell
  • Hotkey – Press Ctrl + L (⌘+ L)

When you open IntelliShell on an existing collection, IntelliShell will open with the default query for that collection. You can use Studio 3T’s Query Manager to set a default query.

IntelliShell in a nutshell

IntelliShell has two main sections: the top Editor section where you can write queries, commands, and scripts, and the bottom Result tab section where you can view the shell output.

MongoDB query auto-completion

IntelliShell detects and auto-suggests JavaScript standard library functions, shell-specific types and methods, operators, collection names, field names, and shell helper commands as you type.

MongoDB query auto-completion

You can trigger query auto-completion in three ways:

  • Button – Click on the database icon, next to Enable Query Assist
  • Right-click – Right-click anywhere in the Editor and choose Open Auto-Completion
  • Hotkey – Press Ctrl + Space (^ + Space)

Live error highlighting

IntelliShell highlights syntax errors as you type.

These errors are also noted in the left-hand sidebar as red crosses that you can hover over, and in the right-hand script overview ruler as clickable red markers that take you straight to the error line.

Error highlighting in IntelliShell

Run queries via the mongo shell (Disable Query Assist)

You can execute queries and scripts entirely, at cursor, or just a selection.

Execute a query

To run an entire script:

  • Button – Click on the Run (play) button in the toolbar
  • Right-click – Right-click anywhere in the Editor and choose Execute Entire Script
  • Hotkey – Press F5

To run a script at cursor, place the cursor at any top-level statement and:

  • Button – Click on the second Run (play) button in the toolbar
  • Right-click – Right-click anywhere in the Editor and choose Execute Statement at Cursor
  • Hotkey – Press F6

To run a selection, highlight the part of the query or script to be executed and:

  • Button – Click on the third Run (play) button
  • Right-click – Right-click anywhere on the selection and choose Execute Selection
  • Hotkey – Press F9

The full list of MongoDB shell operators can be found here, which is also directly accessible within Studio 3T through the Shell Methods Reference link in the toolbar.

In the Result tab section, you’ll always find the Raw Shell Output tab which displays the output of all shell-run commands.

IntelliShell Raw Shell Output tab

Should you choose to disable Query Assist in the toolbar, you enable what was previously the Raw Shell Mode in older IntelliShell versions. Results will appear as text output in the mongo shell.

Whenever possible, Studio 3T will parse documents from the Raw Shell Output and display them in a “prettier” Shell Output Documents tab. You can view results through the three standard views (Table, Tree, and JSON), but they will not be editable.

No editing when Query Assist is off

You can run find and aggregation queries, this way but they will no longer open editable result tabs.

Instead, they will appear along with other shell commands and scripts in the Raw Shell Output tab as you would expect in a real terminal or shell, which means you won’t be able to edit or page through the results. Query Code and Visual Explain will not be available.

Run queries via Studio 3T (Enable Query Assist)

Query Assist is enabled by default for standalone, top-level find and aggregation queries. This means they will be run through Studio 3T instead of the mongo shell.

Query Assist adds functionalities that are not available for shell-run queries, like the ability to:

1. Run find and aggregation queries that open their own powerful result tabs. Find queries run using Query Assist allow in-place editing.

Assisted queries are clearly labeled in the left-hand sidebar as wand icons, and in the right-hand script overview rulers as clickable yellow markers that take you straight to the query.

Open results in separate tabs

Each assisted query will open a separate, editable result tab, whose name will display its corresponding line in the Editor.

2. Edit results within the tabs, as you normally would in other parts of Studio 3T through the three standard views: Table, Tree, and JSON.

Edit results in-place

3. Use Query Code to convert your MongoDB query to JavaScript (Node.js), Java (2.x and 3.x driver API), Python, C#, PHP, and Ruby.

Click on the Query Code button on any result tab.

Query Code button

A Query Code tab will open. Choose your target language from the dropdown menu.

Query Code options

4. Use Visual Explain to help optimize performance by seeing how MongoDB executed your query.

Click on the Explain Query button on any result tab. This will open a new Explain tab that shows which steps MongoDB took to run the query.

Explain in IntelliShell

Query Assist only assists find and aggregation queries – all other scripts and commands will always be run in the shell. Their results are viewable in the the Raw Shell Output tab.

Pin only the query results you want to keep

We’ve done away with the Retain option in the old IntelliShell, which as users have told us, led to undistinguishable tabs and general tab clutter.

Tab clutter
Now you can keep things tidy and choose to keep only the query results you need, by clicking on the Pin result button in any result tab.

Pin results option

All other unpinned result tabs will be cleared with the next execution, be it the entire script or a portion of it.

Format and indent code

There are shortcuts in the IntelliShell toolbar to quickly format and indent code:

Format MongoDB query code

To format code:

  • Button – Click on the Format icon, next to Enable Query Assist
  • Right-click – Right-click anywhere in the Editor and choose Format
  • Hotkey – Press Ctrl + Alt + L (or ⌥ + ⌘ + L on Mac)

To indent code:

  • Button – Place a cursor in the target query/query selection and click on the Indent icon
  • Hotkey – Press Tab

To unindent code:

  • Button – Place a cursor in the target query/query selection and click on the Unindent icon
  • Hotkey – Press Shift + Tab

You can define your Editor tab width preferences under Studio 3T > Preferences > General. The default editor tab width setting is 4 spaces.

Editor tab width preference

Insert and remove comments

It is also possible to comment and uncomment with a line comment.

Place the cursor on the line to be made into a comment and:

  • Right-click – Right-click anywhere in the Editor and choose Comment with Line Comment. Repeat to remove the comment.
  • Hotkey – Press Ctrl + / (⌘+ /). Repeat to remove the comment.

Open and save queries

To save your MongoDB query as a JavaScript file:

  • Button – Click on the Save icon. Alternatively, click on the arrow to find the Save As function.
  • Right-click – Right-click anywhere in the Editor and choose Save Script (As)
  • Hotkeys – Save Script – Ctrl + S (⌘+ S), Save Script As – Shift + Ctrl + S (Shift + ⌘+ S)

To open saved queries:

  • Button – Click on the Open icon
  • Right-click – Right-click anywhere in the Editor and choose Open Script
  • Hotkey – Press Ctrl + O (⌘+ O)

Use IntelliShell and Visual Query Builder side by side

Tired of manually typing everything? You can use Visual Query Builder – our drag-and-drop MongoDB query builder – alongside IntelliShell.

Simply click on Show Visual Query Builder in the toolbar.

IntelliShell and VQB

We’ve tightened this integration so that edits made in IntelliShell are reflected in Visual Query Builder in real-time, and vice versa. This way, you can skip the command line writing and build queries visually – or combine both ways to work even faster.


Want to extend your use of the mongo shell? Read on:

Updated on February 2, 2021

Was this article helpful?

Related Articles