feat: add MongoDB driver - #113
Open
Siyet wants to merge 4 commits into
Open
Conversation
Implement MongoDriver with full DatabaseDriver interface support: - connect/disconnect/ping via official mongodb npm package - execute() parses db.collection.operation() shell syntax (find, findOne, aggregate, countDocuments, distinct, insert/update/delete, createIndex) - getSchema() lists collections with field types inferred from sampling - getTableData() with server-side pagination and sorting - getDDL() shows indexes and schema validation rules - getCompletions() for collection/field autocomplete - getTableObjects() exposes index metadata - getTableStatistics() via collStats command - getEstimatedRowCount()/getTableRowCount() for fast/exact counts Connection form: MongoDB option with authentication database field. Webpack: IgnorePlugin for mongodb optional peer dependencies. Tests: parseMongoCommand unit tests + driver contract spec. Closes #10 https://claude.ai/code/session_01TmxFgxzSzoa1BrV6urdbPk
…hens in collection names - Remove unused `config` field from MongoDriver (stored but never read) - Fix relaxed JSON parser: protect string literals before quoting bare keys so colons inside values (e.g. "test: value") are not corrupted - Expand collection name regex to allow hyphens (e.g. my-collection) https://claude.ai/code/session_013cvrZFra3212F4iH8jmPy3
- Hyphenated collection names (db.my-collection.find) - Hyphenated shorthand (my-events) - Unquoted keys with colons in string values - Unquoted keys with multiple args https://claude.ai/code/session_013cvrZFra3212F4iH8jmPy3
Siyet
commented
Apr 25, 2026
Siyet
left a comment
Owner
Author
There was a problem hiding this comment.
Fixes pushed
fa4d32c— Remove deadconfigfield from MongoDriver (stored inconnect()but never read), fixparseArgsrelaxed JSON regex that corrupted string values containing colons (e.g.{name: "test: value"}→ mangled the value), expand collection name regex to allow hyphens (db.my-collection.find()was rejected).d43cf4e— Add 4 edge case tests for the mongo command parser: hyphenated collection names (full + shorthand), unquoted keys with colons in string values, unquoted keys with multiple args.
Issues to address
src/drivers/mongodb.ts:429—inferBsonTypeclassifies any 24-char hex string asObjectId. AfterflattenDocumentconverts real ObjectIds to hex strings, the type heuristic can't distinguish them from other 24-char hex values (e.g. hash prefixes). This makes the schema column type hint misleading for non-ObjectId hex fields.src/drivers/mongodb.ts:450—inferColumnsuses only the first occurrence of each column to determine its type. If the first row hasnullfor a field and the second row has a string, the column type will benull. Consider iterating all rows or using thesampleFieldsapproach used elsewhere in the driver.
Needs maintainer
- No MongoDB-specific readonly enforcement exists. The command layer's readonly checks are SQL-specific (
SELECT/EXPLAIN/SHOW/WITH). A MongoDB connection marked readonly will still allowinsertOne,updateMany,deleteMany, etc. viaexecute(). Fixing this requires deciding which mongo operations are "read" vs "write" and wiring that into the command layer or the driver itself — touches the readonly contract across modules.
Generated by Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MongoDriverimplementingDatabaseDriverinterface for MongoDB — connect, browse collections, execute shell-like commands (db.collection.find/aggregate/insert/update/delete), view DDL (indexes + validation rules), autocomplete, statisticsCloses #10
Assumptions
execute()command parser requiresdb.<collection>.<operation>(<JSON args>)syntax. Bare collection names are a shorthand forfind({}). MongoDB aggregation framework syntax with$operators works when properly JSON-quoted.admin(standard MongoDB convention).Manual test cases
db.users.find({"age": {"$gt": 25}})→ verify filtered resultsdb.users.aggregate([{"$group": {"_id": "$city", "count": {"$sum": 1}}}])→ verify aggregationdb.users.insertOne({"name": "Test"})→ verify acknowledgement resultChecklist
Generated by Claude Code