Skip to content

Commit b5e060c

Browse files
anandgupta42claude
andcommitted
fix: address multi-model code review findings for MongoDB driver
Fixes from 6-model consensus review (Claude, GPT 5.2 Codex, Gemini 3.1 Pro, Kimi K2.5, MiniMax M2.5, GLM-5): - Cap user-specified `limit` against `effectiveLimit` to prevent OOM from unbounded queries (flagged by Gemini) - Add `ping` command for connection testing instead of querying `system.version` which may not be accessible (flagged by Gemini, GLM-5) - Add `e.code === 26` fallback for `dropCollection` error handling across MongoDB versions (flagged by GLM-5) - Fix misleading docstring on `extractFields` that claimed dot-notation expansion (flagged by Gemini) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent e431850 commit b5e060c

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

‎packages/drivers/src/mongodb.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type MqlCommand =
3232
| "dropCollection"
3333
| "createIndex"
3434
| "listIndexes"
35+
| "ping"
3536

3637
interface MqlQuery {
3738
database?: string
@@ -110,8 +111,8 @@ function inferType(value: unknown): string {
110111
}
111112

112113
/**
113-
* Flatten a document's fields into column entries, handling nested objects
114-
* with dot notation (1 level deep only to keep it manageable).
114+
* Extract field names and their observed types from a set of documents.
115+
* Only inspects top-level fields — nested objects are reported as type "object".
115116
*/
116117
function extractFields(
117118
docs: Record<string, unknown>[],
@@ -260,6 +261,11 @@ export async function connect(config: ConnectionConfig): Promise<Connector> {
260261
const cmd = parsed.command
261262

262263
// Commands that don't need a collection
264+
if (cmd === "ping") {
265+
const result = await db.command({ ping: 1 })
266+
return { columns: ["ok"], rows: [[result.ok]], row_count: 1, truncated: false }
267+
}
268+
263269
if (cmd === "createCollection") {
264270
const name = parsed.name ?? parsed.collection
265271
if (!name) {
@@ -274,7 +280,7 @@ export async function connect(config: ConnectionConfig): Promise<Connector> {
274280
throw new Error("dropCollection requires 'collection'")
275281
}
276282
const dropped = await db.collection(parsed.collection).drop().catch((e: any) => {
277-
if (e.codeName === "NamespaceNotFound") return false
283+
if (e.codeName === "NamespaceNotFound" || e.code === 26) return false
278284
throw e
279285
})
280286
return {
@@ -297,8 +303,10 @@ export async function connect(config: ConnectionConfig): Promise<Connector> {
297303
if (parsed.projection) cursor = cursor.project(parsed.projection)
298304
if (parsed.sort) cursor = cursor.sort(parsed.sort)
299305
if (parsed.skip) cursor = cursor.skip(parsed.skip)
300-
// Fetch one extra to detect truncation
301-
const queryLimit = parsed.limit ?? effectiveLimit
306+
// Cap user-specified limit against effectiveLimit to prevent OOM
307+
const queryLimit = parsed.limit
308+
? Math.min(parsed.limit, effectiveLimit)
309+
: effectiveLimit
302310
cursor = cursor.limit(queryLimit + 1)
303311
const docs = await cursor.toArray()
304312

‎packages/opencode/src/altimate/native/connections/registry.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,9 @@ export async function test(
362362
const config = configs.get(name)
363363
const dbType = config?.type?.toLowerCase()
364364
if (dbType === "mongodb" || dbType === "mongo") {
365-
// MongoDB doesn't support SQL — use a ping-equivalent MQL command
365+
// MongoDB doesn't support SQL — use the standard ping command
366366
await connector.execute(JSON.stringify({
367-
command: "find",
368-
database: (config?.database as string) || "admin",
369-
collection: "system.version",
370-
limit: 1,
367+
command: "ping",
371368
}))
372369
} else {
373370
await connector.execute("SELECT 1")

0 commit comments

Comments
 (0)