User Manual — Back to User Manual
The Interactive Shell is a REPL (Read-Eval-Print Loop) terminal embedded in VS Code. It gives you a command-line experience for DocumentDB and MongoDB API databases, fully integrated with the extension’s connection management. Type a command, see the result, type the next one.
Unlike the Query Playground, which is file-based and suited for multi-statement scripts, the Interactive Shell is designed for quick, ad-hoc exploration: checking what databases exist, browsing collections, running one-off queries, and iterating on results.
Table of Contents
There are several ways to open an Interactive Shell session:

The three inline icons next to each collection node are (from left to right): Open Collection View, New Query Playground, and Open Interactive Shell.
When the shell opens, it displays a connection banner with the host, authentication method, and username. The prompt shows your current database name:
Connected to: mycluster.example.com
Auth: SCRAM-SHA-256 (user: admin)
myDatabase>
The following built-in commands are available at the prompt:
| Command | Description |
|---|---|
show dbs |
List all databases on the server |
show collections |
List all collections in the current database |
use <database> |
Switch to a different database (updates the prompt and tab name) |
it |
Iterate to the next batch of results from the last cursor |
help |
Show available commands and usage information |
exit / quit |
Close the shell session |
cls / clear |
Clear the terminal screen |
Type any DocumentDB API query at the prompt and press Enter:
myDatabase> db.users.find({ status: "active" })
You can use the full query language, including:
db.collection.find(), db.collection.findOne()db.collection.aggregate([...])db.collection.insertOne(), db.collection.updateMany(), db.collection.deleteOne()ObjectId("..."), ISODate("..."), NumberDecimal("...")Date.now(), Math.random(), variables, loopsdb.collection.createIndex(), db.collection.getIndexes()Results are displayed as formatted JSON directly in the terminal, with optional ANSI color coding for readability.
Unlike the Query Playground (where each block runs in a fresh context by default), the Interactive Shell maintains state across commands within a session:
myDatabase> const threshold = 25
myDatabase> db.users.find({ age: { $gt: threshold } })
Variables, functions, and other JavaScript state persist until you close the shell session. This makes it easy to build up complex queries incrementally.
The shell provides two forms of input assistance:

In this example, the shell suggests find(), findOne(), and other methods after typing db.restaurants.find (top). It also suggests the field name reviews as ghost text after the user typed re in a query (bottom). Field suggestions come from schema information gathered locally as you browse and query your data.
Press Tab to trigger completion suggestions based on your current input:
| Context | What Tab Suggests |
|---|---|
| Empty prompt | Shell commands: show, use, db, help, exit, it, … |
After show |
dbs, collections |
After use |
Available database names |
After db. |
Collection names in the current database |
After db.collection. |
Collection methods: find(), aggregate(), insertOne(), … |
When there are multiple matches, the shell inserts the common prefix and displays all options in a multi-column list (similar to bash/zsh). Press Tab again to cycle through them.
As you type, the shell may display a dim, inline suggestion showing what it thinks you’re about to type. For example:
db.users. and see find() appear as ghost textshow and see dbs appearThe shell also suggests closing brackets automatically. When your input has unclosed brackets, parentheses, or braces, the ghost text shows the exact sequence needed to close them. For example:
db.col.find({ _id: { $exists: true and see }}) as ghost textdb.col.aggregate([ { $match: { status: "active" and see } } ]) as ghost textPress Right Arrow or Tab to accept the suggestion, or keep typing to ignore it.
The shell colorizes your input in real time as you type:
| Color | Applied To |
|---|---|
| Cyan | JavaScript keywords, BSON constructors |
| Green | Strings |
| Yellow | Numbers, $-prefixed operators, escape sequences |
| Magenta | Shell commands (show, use, it, etc.) |
| Gray | Comments |
| Red | Regex literals (and unterminated string errors) |
Syntax highlighting can be disabled via the documentDB.shell.display.colorSupport setting for accessibility (screen readers) or piped output.
When a query returns more documents than the batch size (default: 50), the shell displays the first batch and shows a hint:
myDatabase> db.users.find({})
[
{ "_id": ObjectId("..."), "name": "Alice", ... },
...
]
Type "it" for more
Type it and press Enter to fetch the next batch. You can keep typing it until all results are exhausted.
The batch size is controlled by the documentDB.batchSize setting.
If a query is taking too long, press Ctrl+C to cancel it immediately. The shell terminates the running operation and creates a fresh execution context, so you can continue working without restarting the session.
The shell detects incomplete expressions automatically. If you type an opening brace or bracket without closing it, the shell waits for more input instead of trying to execute:
myDatabase> db.orders.aggregate([
... { $group: { _id: "$status", count: { $sum: 1 } } },
... { $sort: { count: -1 } }
... ])
When pasting multi-line text, the shell can handle it in several ways, controlled by the documentDB.shell.multiLinePasteBehavior setting:
| Option | Behavior |
|---|---|
ask (default) |
Prompts you to choose how to process the pasted text |
alwaysAsk |
Always shows the prompt, even if VS Code’s own paste warning is enabled |
executeAsOne |
Joins pasted lines into a single expression and executes |
runLineByLine |
Runs each pasted line independently |
After query results that reference a known collection, the shell shows two clickable action links on the same line:
↗ Collection View [myDatabase.users] ↗ Query Playground [myDatabase.users]
The Interactive Shell is connected to the other query surfaces in the extension:
↗ Collection View link that appears after query results.↗ Query Playground link that appears after query results to open a playground for the same collection.For more details on the Query Playground, see the Query Playground documentation.
The following settings control shell behavior:
| Setting | Default | Description |
|---|---|---|
documentDB.shell.initTimeout |
60 |
Maximum time (in seconds) to wait for the shell to connect during initialization |
documentDB.shell.display.colorSupport |
true |
Enable ANSI color support for syntax highlighting and formatted output. Disable for screen readers or piped output |
documentDB.shell.display.autocompletion |
true |
Enable autocompletion in the Interactive Shell |
documentDB.shell.multiLinePasteBehavior |
ask |
Controls how multi-line text is handled when pasted into the shell |
documentDB.batchSize |
50 |
Number of documents to display per cursor iteration (shared with Query Playground) |
show dbs, db.collection.count()), while the playground is better for multi-step operations you want to save and re-run.show collections before querying: Quickly see what’s available in the current database.use: No need to open a new shell. Just type use otherDatabase and the prompt updates.documentDB.shell.display.colorSupport to false for clean, unformatted output.
Related: Query Playground How It Works Behind the Scenes