feat: implement high-ROI milestone 3 administrative operations#20
feat: implement high-ROI milestone 3 administrative operations#20
Conversation
Add support for 7 commonly-used MongoDB administrative methods: Index Management: - db.collection.createIndex(keys, options?) - db.collection.dropIndex(index) - db.collection.dropIndexes() Collection Management: - db.collection.drop() - db.collection.renameCollection(newName, dropTarget?) Database Management: - db.createCollection(name) - db.dropDatabase() Lower-ROI methods (stats, serverStatus, etc.) remain as planned operations with PlannedOperationError for fallback to mongosh. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR implements the high-ROI subset of MongoDB administrative operations (indexes, collections, and database-level) in the translator and executor layers, with corresponding integration tests across MongoDB and DocumentDB. Lower-ROI admin methods remain planned-only with fallback via PlannedOperationError.
Changes:
- Extend the translator with new operation types (
OpCreateIndex,OpDropIndex,OpDropIndexes,OpDrop,OpCreateCollection,OpDropDatabase,OpRenameCollection) and argument extraction for the corresponding shell methods and db statements. - Add executor implementations for the new administrative operations, including index creation/deletion, collection creation/deletion/rename, and database drop, plus a MongoDB-only test runner helper.
- Update the method registry and error tests to reflect the reduced set of planned-only methods, and add comprehensive integration tests for all implemented admin operations.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
internal/translator/visitor.go |
Routes new db statements and collection methods to the appropriate M3 administrative OpType values and extraction helpers. |
internal/translator/types.go |
Introduces new OperationType values and fields on Operation for index and collection admin metadata (keys, names, rename flags), plus a placeholder IndexModel type. |
internal/translator/method_registry.go |
Shrinks the planned-method registry to only lower-ROI administrative methods, removing entries for now-implemented admin operations. |
internal/translator/database.go |
Adds argument extraction for db.createCollection(...), validating and storing the target collection name. |
internal/translator/collection.go |
Implements argument extraction for createIndex, dropIndex, dropIndexes, and renameCollection, including validation and translation into Operation fields. |
internal/testutil/container.go |
Adds RunOnMongoDBOnly helper to run tests on MongoDB instances while skipping DocumentDB (needed for renameCollection). |
internal/executor/executor.go |
Wires new administrative OpTypes into the dispatcher and forwards them to dedicated admin executor functions. |
internal/executor/admin.go |
Implements execution of index, collection, and database admin commands against the Go MongoDB driver, including helper functions for index key comparison. |
error_test.go |
Adjusts planned-operation tests to use createIndexes instead of createIndex and updates method registry stats to the new planned-method count. |
admin_test.go |
Adds integration tests for create/drop indexes, create/drop collection, drop database, and rename collection (with and without dropTarget), including multi-backend coverage and MongoDB-only scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- createCollection(): reject options argument (not supported yet) - dropIndexes(): reject array argument instead of silently dropping all - createIndex(): reject unsupported options instead of ignoring them - Remove unused IndexModels field and IndexModel type Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Address PR review feedback by implementing proper support instead of rejecting unsupported features: createCollection options: - capped: boolean for capped collections - size: size in bytes for capped collections - max: max documents for capped collections - validator: validation rules document - validationLevel/validationAction: validation settings createIndex options: - unique: boolean for unique indexes - sparse: boolean for sparse indexes - expireAfterSeconds: TTL index support - background: accepted but deprecated (no-op) dropIndexes enhancements: - Support array of index names to drop multiple specific indexes Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address PR review comment about duplicate toInt64 helper by: - Exporting ToInt64 and ToInt32 from translator/helpers.go - Removing duplicate toInt64 from executor/admin.go - Using translator.ToInt64 in executor for numeric comparisons Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary
Implemented Methods
Index Management:
db.collection.createIndex(keys, options?)- Create a single indexdb.collection.dropIndex(index)- Drop index by name or key specdb.collection.dropIndexes()- Drop all indexes (except _id)Collection Management:
db.collection.drop()- Drop a collectiondb.collection.renameCollection(newName, dropTarget?)- Rename a collectionDatabase Management:
db.createCollection(name)- Create a new collectiondb.dropDatabase()- Drop the current databaseNot Implemented (Lower ROI)
These remain as planned operations with
PlannedOperationError:createIndexes(batch index creation)stats(),serverStatus(),serverBuildInfo(), etc.dataSize,storageSize, etc.)Test plan
renameCollectiontests run only on MongoDB (not supported by DocumentDB)🤖 Generated with Claude Code