Run your first query
Open a collection, run a find, read the result six different ways, and find out whether it used an index.
Open a collection
Double-click a collection in the sidebar. That opens a query tab bound to that connection and
database, with a find already written for you.
Ctrl+K (Cmd+K on macOS) opens the command palette, which searches every connection, database,
and collection at once, and > reaches the commands. It is usually faster than the tree once you know what you are
looking for.
Write the query
The editor is Monaco, running against the MongoDB Node driver, so the syntax is the syntax you already know:
db.orders.find({ status: { $ne: 'cancelled' } }).sort({ placedAt: -1 })
Completions come from your actual collection schemas, not from a static list of operators. Type a
field name and you get its real BSON type; type address. and you get the child fields under it.
The part worth knowing about is what happens inside a pipeline. The editor folds the pipeline
stage by stage: $project, $group, $count, $facet, $bucket and $unset reshape the result,
and $addFields, $set and $lookup add to it. A field introduced by an earlier stage is still
offered to you eight stages later. Where a stage’s output cannot be derived, the whole document is
kept rather than guessed at, so valid code is never reported as an error. Schema-aware autocomplete has
the full behaviour.
Run it with Ctrl+Enter. Queries and Markdown notes autosave, so a tab you closed by accident comes
back with its text.
Read the result
The result pane has six views, and the one you want depends on the question:
| View | Use it for |
|---|---|
| Table | Scanning many documents with the same shape |
| Tree | One document at a time, with the BSON type of every value |
| JSON | Copying the raw Extended JSON out |
| Result | A write outcome, or a single value |
| Explain | Whether the query used an index, and how efficiently |
| Chart | Seeing the shape of the numbers (Pro) |
Switch with the buttons above the result. Ctrl+I opens a preview drawer that follows the focused
row.
Check that it used an index
This is the habit worth forming early. Auto-explain collects plan statistics while a read runs, so the result reports its scan type without you running a second query. Hovering that badge details the plan: scan type, index name, documents scanned, and documents returned.
If it scanned the collection, open the Explain view. It grades the plan as collection scan, indexed, optimal, or ungraded, shows the execution plan as a tree, and suggests the index that would remove the scan, with a button that creates it.
You can also paste an explain plan from anywhere else into the explain visualizer, which runs in the browser with nothing installed.
Next
- Query editor and environment for the JavaScript sandbox
- Result views for everything the result pane does
- Reading an explain plan for what the grade actually measures