Skip to content

Commit 56acab4

Browse files
anandgupta42claude
andcommitted
fix: address CodeRabbit findings and update docs for MongoDB driver
CodeRabbit review fixes: - Use `...COMMON_ALIASES` spread in `MONGODB_ALIASES` for consistency with other drivers (normalize.ts) - Scan entire aggregate pipeline for `$limit` instead of only last stage; also skip auto-limit for `$out`/`$merge` write pipelines - Keep `mongodb` at `^6.0.0` (NOT upgrading to v7): v7 drops Node 16/18 support and has many breaking changes; v6.21.0 is actively maintained and supports MongoDB server 3.6-8.0 Additional review fixes: - Include database name in URI when building from individual config fields for correct auth-source resolution (GLM-5) - Add security comment about credential exposure in URI (Kimi K2.5) Documentation updates: - `docs/docs/drivers.md`: add MongoDB to support matrix (11 databases), install section, auth methods, auto-discovery - `docs/docs/configure/warehouses.md`: add MongoDB configuration section with connection string and field-based examples, server compatibility - `docs/docs/data-engineering/tools/warehouse-tools.md`: add MongoDB to Docker discovery and env var detection Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent b5e060c commit 56acab4

5 files changed

Lines changed: 73 additions & 12 deletions

File tree

‎docs/docs/configure/warehouses.md‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Warehouses
22

3-
Altimate Code connects to 8 warehouse types. Configure them in `.altimate-code/connections.json` (project-local) or `~/.altimate-code/connections.json` (global).
3+
Altimate Code connects to 9 warehouse types. Configure them in `.altimate-code/connections.json` (project-local) or `~/.altimate-code/connections.json` (global).
44

55
## Configuration
66

@@ -237,6 +237,51 @@ If you're already authenticated via `gcloud`, omit `credentials_path`:
237237
| `ssl_cert` | No | Path to client certificate file |
238238
| `ssl_key` | No | Path to client key file |
239239

240+
## MongoDB
241+
242+
```json
243+
{
244+
"my-mongodb": {
245+
"type": "mongodb",
246+
"host": "localhost",
247+
"port": 27017,
248+
"database": "analytics",
249+
"user": "analyst",
250+
"password": "{env:MONGO_PASSWORD}"
251+
}
252+
}
253+
```
254+
255+
| Field | Required | Description |
256+
|-------|----------|-------------|
257+
| `connection_string` | No | Full connection string (alternative to individual fields) |
258+
| `host` | No | Hostname (default: `127.0.0.1`) |
259+
| `port` | No | Port (default: `27017`) |
260+
| `database` | No | Database name |
261+
| `user` | No | Username |
262+
| `password` | No | Password |
263+
| `auth_source` | No | Authentication database (default: `admin`) |
264+
| `replica_set` | No | Replica set name |
265+
| `tls` | No | Enable TLS (default: `false`) |
266+
| `direct_connection` | No | Connect directly to a single host |
267+
268+
### Using a connection string
269+
270+
```json
271+
{
272+
"my-mongodb": {
273+
"type": "mongodb",
274+
"connection_string": "mongodb://analyst:secret@localhost:27017/analytics"
275+
}
276+
}
277+
```
278+
279+
!!! note
280+
MongoDB uses MQL (MongoDB Query Language) instead of SQL. Queries are submitted as JSON objects via the `execute` method. Supported commands: `find`, `aggregate`, `countDocuments`, `distinct`, `insertOne`, `insertMany`, `updateOne`, `updateMany`, `deleteOne`, `deleteMany`, `createIndex`, `listIndexes`, `createCollection`, `dropCollection`, `ping`.
281+
282+
!!! info "Server compatibility"
283+
The MongoDB driver (v6.x) supports MongoDB server versions 3.6 through 8.0, covering all releases from the last 3+ years.
284+
240285
## SQL Server
241286

242287
```json

‎docs/docs/data-engineering/tools/warehouse-tools.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ env_bigquery | bigquery | GOOGLE_APPLICATION_CREDENTIALS
7070
| Databricks | `DATABRICKS_HOST`, `DATABRICKS_SERVER_HOSTNAME` |
7171
| PostgreSQL | `PGHOST`, `PGDATABASE`, `DATABASE_URL` |
7272
| MySQL | `MYSQL_HOST`, `MYSQL_DATABASE` |
73+
| MongoDB | `MONGODB_URI`, `MONGO_URL` |
7374
| Redshift | `REDSHIFT_HOST` |
7475

7576
### Parameters
@@ -164,7 +165,7 @@ Remove an existing warehouse connection.
164165

165166
## warehouse_discover
166167

167-
Discover database containers running in Docker. Detects PostgreSQL, MySQL/MariaDB, and SQL Server containers with their connection details.
168+
Discover database containers running in Docker. Detects PostgreSQL, MySQL/MariaDB, SQL Server, and MongoDB containers with their connection details.
168169

169170
```
170171
> warehouse_discover

‎docs/docs/drivers.md‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Overview
44

5-
Altimate Code connects to 10 databases natively via TypeScript drivers. No Python dependency required. Drivers are loaded lazily, so only the driver you need is imported at runtime.
5+
Altimate Code connects to 11 databases natively via TypeScript drivers. No Python dependency required. Drivers are loaded lazily, so only the driver you need is imported at runtime.
66

77
## Support Matrix
88

@@ -17,6 +17,7 @@ Altimate Code connects to 10 databases natively via TypeScript drivers. No Pytho
1717
| Snowflake | `snowflake-sdk` | Password, Key-Pair (unencrypted + encrypted), OAuth | ✅ Live account | 37 E2E tests, key-pair with passphrase support |
1818
| BigQuery | `@google-cloud/bigquery` | Service Account, ADC | ✅ Live account | 25 E2E tests, UNNEST/STRUCT/DATE types |
1919
| Databricks | `@databricks/sql` | PAT, OAuth | ✅ Live account | 24 E2E tests, Unity Catalog support |
20+
| MongoDB | `mongodb` | Password, Connection String | ✅ Docker | 90 E2E tests, MQL queries, aggregation pipelines |
2021
| Oracle | `oracledb` (thin) | Password | ❌ Needs Oracle 12.1+ | Thin mode only, no Instant Client |
2122

2223
## Installation
@@ -33,6 +34,9 @@ bun add pg # PostgreSQL + Redshift
3334
bun add mysql2 # MySQL
3435
bun add mssql # SQL Server
3536

37+
# Document databases
38+
bun add mongodb # MongoDB
39+
3640
# Cloud warehouses
3741
bun add snowflake-sdk # Snowflake
3842
bun add @google-cloud/bigquery # BigQuery
@@ -129,6 +133,14 @@ altimate-dbt init --project-root /path/to/dbt/project --python-path $(which pyth
129133
|--------|--------------|
130134
| Password | `host`, `port`, `service_name`, `user`, `password` |
131135

136+
### MongoDB
137+
| Method | Config Fields |
138+
|--------|--------------|
139+
| Password | `host`, `port`, `database`, `user`, `password` |
140+
| Connection String | `connection_string: "mongodb://user:pass@host:port/db"` |
141+
142+
MongoDB supports server versions 3.6 through 8.0. Queries use MQL (MongoDB Query Language) via JSON, not SQL. The driver supports `find`, `aggregate`, CRUD operations, index management, and schema introspection via document sampling.
143+
132144
### DuckDB
133145
| Method | Config Fields |
134146
|--------|--------------|
@@ -167,7 +179,7 @@ SSH auth types: `"key"` (default) or `"password"` (set `ssh_password`).
167179

168180
The CLI auto-discovers connections from:
169181

170-
1. **Docker containers**: detects running PostgreSQL, MySQL, MariaDB, SQL Server, Oracle containers
182+
1. **Docker containers**: detects running PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, MongoDB containers
171183
2. **dbt profiles**: parses `~/.dbt/profiles.yml` for all supported adapters
172184
3. **Environment variables**: detects `SNOWFLAKE_ACCOUNT`, `PGHOST`, `MYSQL_HOST`, `MSSQL_HOST`, `ORACLE_HOST`, `DUCKDB_PATH`, `SQLITE_PATH`, etc.
173185

‎packages/drivers/src/mongodb.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ export async function connect(config: ConnectionConfig): Promise<Connector> {
197197
return {
198198
async connect() {
199199
// Support connection_string or individual fields
200+
// SECURITY: URI may contain credentials — never log it
200201
let uri: string
201202
if (config.connection_string) {
202203
uri = config.connection_string as string
@@ -205,11 +206,13 @@ export async function connect(config: ConnectionConfig): Promise<Connector> {
205206
const port = (config.port as number) ?? 27017
206207
const user = config.user as string | undefined
207208
const password = config.password as string | undefined
209+
// Include database in URI for correct auth-source resolution
210+
const dbPath = explicitDb ? `/${encodeURIComponent(explicitDb)}` : ""
208211

209212
if (user && password) {
210-
uri = `mongodb://${encodeURIComponent(user)}:${encodeURIComponent(password)}@${host}:${port}`
213+
uri = `mongodb://${encodeURIComponent(user)}:${encodeURIComponent(password)}@${host}:${port}${dbPath}`
211214
} else {
212-
uri = `mongodb://${host}:${port}`
215+
uri = `mongodb://${host}:${port}${dbPath}`
213216
}
214217
}
215218

@@ -337,11 +340,12 @@ export async function connect(config: ConnectionConfig): Promise<Connector> {
337340
if (!parsed.pipeline || !Array.isArray(parsed.pipeline)) {
338341
throw new Error("aggregate requires a 'pipeline' array")
339342
}
340-
// Append $limit if the pipeline doesn't already end with one
343+
// Append $limit if the pipeline doesn't already contain one anywhere.
344+
// Also skip for $out/$merge pipelines which write results.
341345
const pipeline = [...parsed.pipeline]
342-
const lastStage = pipeline[pipeline.length - 1]
343-
const hasLimit = lastStage && "$limit" in lastStage
344-
if (!hasLimit) {
346+
const hasLimit = pipeline.some((stage) => "$limit" in stage)
347+
const hasWrite = pipeline.some((stage) => "$out" in stage || "$merge" in stage)
348+
if (!hasLimit && !hasWrite) {
345349
pipeline.push({ $limit: effectiveLimit + 1 })
346350
}
347351

‎packages/drivers/src/normalize.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ const ORACLE_ALIASES: AliasMap = {
7474
}
7575

7676
const MONGODB_ALIASES: AliasMap = {
77-
user: ["username"],
78-
database: ["dbname", "db"],
77+
...COMMON_ALIASES,
7978
connection_string: ["connectionString", "uri", "url"],
8079
auth_source: ["authSource"],
8180
replica_set: ["replicaSet"],

0 commit comments

Comments
 (0)