# MongoDB

MongoDB opens in a document workspace. It browses collections, runs find and aggregate with Extended JSON, shows documents without losing their types, and stages changes that are checked against the server before they are written.

## Where to find it

| Action | How |
| --- | --- |
| Create a connection | `New connection`, `⌘N` (`Ctrl+N`), then `MongoDB` |
| Open the workspace | `Connect` on a saved connection |
| Choose a collection | `Databases and collections` on the left |
| Query | `Find` or `Aggregate` above the grid, then `Run` |
| Inspect a document | Select a row, then read `Canonical Extended JSON` on the right |
| Stage and commit | `Document draft`, `Staged operations` and `Commit staged operations` on the right |
| Switch connection | `⌘⇧K` (`Ctrl+Shift+K`) |
Databases and collections sit on the left, the query and the grid in the middle, and the inspector and staged operations on the right.

## Connecting

Choose `MongoDB` in `New connection` and enter a `mongodb://` seed list or a `mongodb+srv://` address in `Connection URI`. Keep credentials out of the URI: `Username`, `Authentication database` and `Password` have their own fields, and the password goes to the keychain only when you check `Save to system keychain`.

`Verify TLS certificates` is on by default and required for SRV, and `Direct connection` talks to one host without replica set discovery. Client certificates, Kerberos, LDAP, OIDC and cloud credentials have no fields.

## Browsing

Select a database, then a collection, then `Run`. The grid shows 100 documents per page with a column for every top-level field on the page, and the arrows below it move between pages. A field a document does not have reads `missing` in italics, while a field set to null shows a `null` badge.

## Queries

`Find` takes a `Filter`, a `Projection` and a `Sort`, each an Extended JSON object. `Aggregate` takes an `Aggregation pipeline` as an Extended JSON array, and rejects output stages that write, because writes go through staging. The editors accept document syntax only and do not run mongosh JavaScript.

## Inspecting

Select a row and `Canonical Extended JSON` shows the whole document. ObjectId, Decimal128, dates, binary data and 64-bit integers keep their type tags, so a value is never rounded or turned into a plain string. The same text fills `Document draft`, ready to edit.

## Editing

`Stage insert` adds the draft as a new document, `Stage update` replaces the selected document with the draft, and `Stage delete` removes the selected document. Each entry in `Staged operations` opens to show the original document and its `_id` beside the replacement.

`Commit staged operations` writes only when the document on the server still matches the original. A document changed by someone else is reported as changed or deleted before commit and stays staged, and the app never retries it.

## Good to know

- `Commit as a transaction` is available only when discovery finds a replica set or sharded cluster that supports transactions. Without it, each operation is written on its own and the result names each failure.
- A read-only connection refuses every write in the native layer.
- `Query history` keeps the last 30 queries of the session, and a server error stays above the grid until the next run.
- There is no cancellation, schema editing, diagram, import, export or snapshot here, because collections hold documents of any shape rather than a relational schema.

## Related

- [Connections](https://bobbytables.app/docs/connections.md)
- [Safe mode, read-only mode and the console](https://bobbytables.app/docs/safe-mode.md)
- [Redis and Valkey](https://bobbytables.app/docs/redis.md)
- [Cassandra and ScyllaDB](https://bobbytables.app/docs/cassandra.md)
