> ## Documentation Index
> Fetch the complete documentation index at: https://snapr.seshuk.im/llms.txt
> Use this file to discover all available pages before exploring further.

# MongoDB

> Back up MongoDB with mongodump: connection URI or host/port, oplog support, collection excludes, and extra flags.

`type: mongodb` uses `mongodump` to back up a single database, all databases, or whatever a connection URI points at.

## Example

```yaml snapr.yaml theme={null}
sources:
  - type: mongodb
    uri: env:MONGO_URI
    oplog: true
```

## Options

| Option          | Type      | Required | Default     | Description                                                                                                              |
| --------------- | --------- | -------- | ----------- | ------------------------------------------------------------------------------------------------------------------------ |
| `type`          | `mongodb` | Yes      |             |                                                                                                                          |
| `uri`           | string    | Yes\*    |             | Full Mongo URI. When set, the host/port/credential fields below are ignored. Use `env:`.                                 |
| `host`          | string    | No       | `127.0.0.1` | Ignored when `uri` is set.                                                                                               |
| `port`          | int       | No       | `27017`     |                                                                                                                          |
| `username`      | string    | No       |             |                                                                                                                          |
| `password`      | string    | No       |             | Passed as `--password=...` on the command line. Use `env:`, and prefer `uri` to keep secrets out of the process listing. |
| `database`      | string    | Yes\*    |             | Required unless `allDatabases: true` or `uri` is set.                                                                    |
| `allDatabases`  | bool      | No       | `false`     | Omits `--db` so `mongodump` dumps every database.                                                                        |
| `authDatabase`  | string    | No       |             | Passed as `--authenticationDatabase` (typically `admin`).                                                                |
| `oplog`         | bool      | No       | `false`     | Include the oplog for point-in-time consistency. Requires a replica set.                                                 |
| `excludeTables` | string\[] | No       |             | Each entry becomes an `--excludeCollection` flag.                                                                        |
| `extraParams`   | map       | No       |             | Extra `mongodump` flags.                                                                                                 |

## Requirements

* `mongodump` must be installed on the snapr host and available in `PATH`.
* `mongodump` ships in the [MongoDB Database Tools](https://www.mongodb.com/try/download/database-tools) package, which is distributed separately from the MongoDB server.
* The configured user needs the `backup` role, or equivalent read access on the target database plus `clusterMonitor` for `--oplog`.

## Notes

* `oplog: true` requires a replica set (a single-node replica set works) and `mongodump` only accepts `--oplog` for full dumps — do not combine it with `database`.
* When using `uri`, embed credentials in the URI string itself; the `username` and `password` fields are ignored.
* `extraParams` keys are prefixed with `--`. Use an empty string value for boolean flags.

### Host and port

```yaml snapr.yaml theme={null}
sources:
  - type: mongodb
    host: mongo.internal
    port: 27017
    username: backup
    password: env:MONGO_PASSWORD
    authDatabase: admin
    database: app
    excludeTables:
      - sessions
      - audit
    extraParams:
      gzip: ''
      numParallelCollections: '4'
```

## Related

* [Sources overview](/configuration/sources/overview)
