feat: add utility commands support (show dbs, show collections, getCollectionNames) - #4
Conversation
…llectionNames) Add support for MongoDB shell utility commands: - `show dbs` / `show databases` - list all databases - `show collections` - list collections in current database - `db.getCollectionNames()` - list collection names in current database 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This pull request adds support for MongoDB utility commands to list databases and collections, enabling show dbs, show databases, show collections, and db.getCollectionNames() operations. This completes step 4 of the MVP implementation.
Changes:
- Added three new operation types (
opShowDatabases,opShowCollections,opGetCollectionNames) to support utility commands - Implemented shell command visitor to handle
show dbs/databasesandshow collectionscommands - Added execution functions that call MongoDB driver's
ListDatabaseNames()andListCollectionNames()APIs
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| translator.go | Added new operation types and shell command visitor to parse show dbs/databases, show collections, and db.getCollectionNames() commands |
| executor.go | Implemented execution functions for the new utility commands using MongoDB driver APIs |
| executor_test.go | Added comprehensive test coverage for all three utility commands with database and collection setup |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| rows := make([]string, len(names)) | ||
| copy(rows, names) |
There was a problem hiding this comment.
The copy operation is unnecessary here. Since names is already a []string, you can directly assign it to rows instead of creating a new slice and copying. This simplifies the code: rows := names.
| rows := make([]string, len(names)) | ||
| copy(rows, names) |
There was a problem hiding this comment.
The copy operation is unnecessary here. Since names is already a []string, you can directly assign it to rows instead of creating a new slice and copying. This simplifies the code: rows := names.
Summary
show dbs/show databases- lists all databases usingclient.ListDatabaseNames()show collections- lists collections in current database usingdb.ListCollectionNames()db.getCollectionNames()- lists collection names (same as show collections)This completes step 4 of the MVP implementation as specified in the design document.
Test plan
TestShowDatabases- verifiesshow dbsandshow databasesreturn database namesTestShowCollections- verifiesshow collectionsreturns collection namesTestGetCollectionNames- verifiesdb.getCollectionNames()returns collection names🤖 Generated with Claude Code