Skip to content

fix: MongoDB database switch, dotted collection names, and shell parser#141

Merged
datlechin merged 1 commit intomainfrom
fix/mongodb-database-switch-and-parser
Mar 2, 2026
Merged

fix: MongoDB database switch, dotted collection names, and shell parser#141
datlechin merged 1 commit intomainfrom
fix/mongodb-database-switch-and-parser

Conversation

@datlechin
Copy link
Copy Markdown
Member

Summary

  • Fix Cmd+K database switch not updating sidebar collections for MongoDB connections
  • Fix dotted collection names (e.g. system.version) being misparsed in shell syntax
  • Add bracket notation (db["collection"]) support and db-level method handling to MongoShellParser

Changes

Database switch fix

  • MongoDBDriver.connection changed from let to private(set) var with switchDatabase(to:) method
  • Coordinator now updates driver + metadata driver connection before session update
  • Added .refreshData notification post (matching PostgreSQL branch)
  • SidebarViewModel uses forceLoadTables() from notifications to prevent race conditions with stale schemaProvider cache

Dotted collection name support

  • Parser now splits on last . before first ( instead of first ., so db.system.version.find() correctly parses as collection=system.version
  • All MongoDB query generation converted to bracket notation db["collection"] across MongoDBStatementGenerator, TableOperations, QueryTab, ExportService, and MongoDBDriver DDL

Shell parser improvements

  • Added parseBracketExpression() for db["collection"].method() syntax
  • Added parseDbLevelMethod() for db.getCollectionNames(), db.listCollections(), db.createCollection(), db.dropDatabase(), db.version(), db.stats()
  • Added guard for db. with empty collection name

Test plan

  • 96 MongoShellParser tests pass (65 new)
  • 32 MongoDBStatementGenerator tests pass (3 updated for bracket notation)
  • 199 total MongoDB tests pass
  • Manual: connect to MongoDB, switch database via Cmd+K, verify sidebar refreshes
  • Manual: open a dotted collection (e.g. system.version), verify CRUD operations work

@datlechin datlechin merged commit afc0529 into main Mar 2, 2026
1 check passed
@datlechin datlechin deleted the fix/mongodb-database-switch-and-parser branch March 2, 2026 12:19
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 109202785e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +216 to +217
let argAndRest = try extractParenthesizedArgAndRemainder(from: input, startingAt: parenIndex)
let arg = argAndRest.arg
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject trailing tokens in db-level method parsing

parseDbLevelMethod parses the parenthesized argument but ignores the returned remainder, so malformed input like db.dropDatabase()foo is accepted and executed as a real dropDatabase command instead of throwing syntax error. This is especially dangerous for destructive db-level operations introduced in this change, because a typo after ) can still run the command.

Useful? React with 👍 / 👎.

Comment on lines +209 to +213
func forceLoadTables() {
loadTask?.cancel()
loadTask = nil
isLoading = false
loadTables()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Prevent canceled table loads from overwriting fresh sidebar data

forceLoadTables() cancels the previous task and immediately starts a new load, but the canceled task is not awaited and loadTablesAsync() has no cancellation guard before writing tables. If the first fetch completes after the replacement fetch (e.g., during MongoDB database switching), stale results can overwrite the newly loaded table list and reintroduce the wrong sidebar state.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant