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

# Database imports

> Import rows and documents from PostgreSQL, MySQL, SQLite, MongoDB, Firestore, DynamoDB, Redis, and Elasticsearch.

Each row or document becomes a markdown page with its fields in frontmatter. Every source also accepts the [common flags](https://docs.kiwifs.com/import/overview.md#common-flags): `--prefix`, `--id-column`, `--columns`, `--limit`, and `--dry-run`.

## SQL databases

> [tab] PostgreSQL
>
> ```bash Terminal theme={null}
> kiwifs import --from postgres \
>   --dsn "postgres://user:pass@localhost:5432/mydb" \
>   --table users \
>   --prefix people \
>   --root ./knowledge
> ```

> [tab] MySQL
>
> ```bash Terminal theme={null}
> kiwifs import --from mysql \
>   --dsn "user:pass@tcp(localhost:3306)/mydb" \
>   --table articles \
>   --root ./knowledge
> ```
>
> The DSN uses the Go MySQL driver format.

> [tab] SQLite
>
> ```bash Terminal theme={null}
> kiwifs import --from sqlite \
>   --db ./data.db \
>   --table entries \
>   --root ./knowledge
> ```

| Flag | Description |
| - | - |
| `--dsn` | Connection string. Required for `postgres` and `mysql`. |
| `--db` | Path to the database file. Required for `sqlite`. |
| `--table` | Table to import. Required unless you pass `--query`. |
| `--query` | Custom `SELECT` that replaces the table scan. |

When you pass `--table`, KiwiFS detects the table's primary key and uses it as the file name. With `--query`, set `--prefix` and `--id-column` yourself, because there is no table name or key to fall back on.

```bash Terminal theme={null}
kiwifs import --from postgres \
  --dsn "postgres://user:pass@localhost/mydb" \
  --query "SELECT id, name, email FROM users WHERE active = true" \
  --id-column id \
  --prefix active-users
```

## MongoDB

```bash Terminal theme={null}
kiwifs import --from mongodb \
  --uri "mongodb://localhost:27017" \
  --database myapp \
  --collection articles
```

| Flag | Description |
| - | - |
| `--uri` | MongoDB connection URI (required) |
| `--database` | Database name (required) |
| `--collection` | Collection name (required) |

The document `_id` becomes the file name.

## Firestore

```bash Terminal theme={null}
kiwifs import --from firestore \
  --project my-gcp-project \
  --collection users
```

| Flag | Description |
| - | - |
| `--project` | GCP project ID (required) |
| `--collection` | Collection name (required) |

The CLI uses Application Default Credentials. Set `GOOGLE_APPLICATION_CREDENTIALS` or run inside GCP. Over REST you can instead send the service account JSON in the `credentials` field.

## DynamoDB

```bash Terminal theme={null}
kiwifs import --from dynamodb \
  --region us-east-1 \
  --table my-table
```

| Flag | Description |
| - | - |
| `--region` | AWS region (required) |
| `--table` | Table name (required) |

KiwiFS uses the default AWS credential chain (`AWS_PROFILE`, `~/.aws/credentials`, or an IAM role). Set `AWS_ENDPOINT_URL` to point at DynamoDB Local or another compatible endpoint.

## Redis

```bash Terminal theme={null}
kiwifs import --from redis \
  --addr localhost:6379 \
  --pattern "article:*"
```

| Flag | Default | Description |
| - | - | - |
| `--addr` | | Redis address (required) |
| `--password` | | Redis password |
| `--redis-db` | `0` | Database number |
| `--pattern` | `*` | Key glob to scan |

Each matching key becomes one page, and the default prefix is `redis`. How the value maps to frontmatter depends on the key type:

| Key type | Frontmatter |
| - | - |
| Hash | One field per hash field |
| String holding a JSON object | One field per JSON key |
| Other string | `value` |
| List | `items` |
| Set | `members` |
| Sorted set | `items`, each with `member` and `score` |

The key becomes the file name, with `:`, `/`, and spaces replaced by `_`. For example, `article:42` becomes `redis/article_42.md`.

## Elasticsearch

```bash Terminal theme={null}
kiwifs import --from elasticsearch \
  --url http://localhost:9200 \
  --index articles
```

| Flag | Description |
| - | - |
| `--url` | Cluster URL (required). Put credentials in the URL if the cluster needs them. |
| `--index` | Index to import (required) |

KiwiFS scrolls through every document in the index with a `match_all` query. The document `_id` becomes the file name.

## From the API or an agent

PostgreSQL, MySQL, SQLite, MongoDB, and Firestore are also available over REST and MCP. The request fields match the CLI flags in snake case.

> [tab] REST
>
> ```bash Terminal theme={null}
> curl -X POST http://localhost:3333/api/kiwi/import \
>   -H "Content-Type: application/json" \
>   -d '{
>     "from": "postgres",
>     "dsn": "postgres://user:pass@db:5432/mydb",
>     "table": "users",
>     "prefix": "people",
>     "dry_run": true
>   }'
> ```
>
> ```json Response theme={null}
> { "imported": 120, "skipped": 0, "errors": [] }
> ```

> [tab] MCP
>
> ```json kiwi_import theme={null}
> {
>   "from": "postgres",
>   "dsn": "postgres://user:pass@localhost/mydb",
>   "table": "users",
>   "prefix": "people",
>   "dry_run": true
> }
> ```

> [!TIP]
>
> A successful REST import of PostgreSQL, MySQL, MongoDB, or Firestore saves the connection and turns on hourly auto-sync. See [Saved connections](https://docs.kiwifs.com/import/connections.md#saved-connections) to change or pause it.

## Related

> [card] [Import overview](https://docs.kiwifs.com/import/overview.md)
>
> Output format, common flags, and re-import rules.

> [card] [Browse, preview, and sync](https://docs.kiwifs.com/import/connections.md)
>
> List tables and preview rows before importing.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.