fix(plugin-mongodb): parse db.getCollection and align exported columns (#1971) - #1973
Merged
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
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.
Fixes #1971.
The bug
Exporting a MongoDB collection fails for every format with
Unsupported MongoDB method: getCollection, before any data is read.MongoShellParser.parseDbExpressionsplits a statement at the last dot before the first(. Fordb.getCollection("users").find({})there is no dot beforegetCollection(, so the parser routes it toparseDbLevelMethod, which treatsgetCollectionas a database method and throws. The string comes fromMongoDBPluginDriver.defaultExportQuery, so the export dies before libmongoc is ever called.The generator was right and the parser was wrong.
db.getCollection()is the documented mongosh accessor, and the only way to reach a collection whose name has dots or spaces, starts with a digit, or matches a database method such asstats. Studio 3T, NoSQLBooster, and DataGrip all generate it.The fix
Parser (
MongoShellParser). Adding a case to the database-method switch would not have worked, sinceparseDbLevelMethoddiscards the remainder and.find({})would have vanished. The real defect was that the parser modelled collection references ad hoc in two disconnected places with no room for a third. There is now one string-literal reader (double quotes, single quotes, backticks), onegetCollectionaccessor path that treats the name as opaque so dots inside it stay part of the name, and one shared chain resolver used by all three accessor forms.db["name"]keeps its behaviour and gains backtick support, and its hand-rolled escape loop is gone.db.getSiblingDB(...)still throws an unsupported-method error on purpose. A query always runs against the connected database, so accepting a cross-database accessor would silently read from the wrong one.Export query (
MongoDBQueryBuilder,MongoDBPluginDriver).defaultExportQueryhand-rolled a third accessor form with no escaping, so a collection name containing a quote or a backslash produced a malformed query. It now calls the newbuildExportQuery(collection:), so browse, filter, count, and export all render names through the same accessor.Streamed columns (
MongoDBConnection+SyncHelpers, newMongoStreamProjection). With the parse fixed, export still wrote bad files. The header was built from the first document alone, then columns grew for later documents without being re-announced: CSV rows ended up wider than their header, and JSON dropped those fields from every document. Since MongoDB collections are schemaless, that hits any collection with an optional field. Streaming now buffers a bounded sample, derives the column union from it, emits the header once, flushes the buffered rows, and projects everything after that onto the fixed header. Columns never grow after the header, so rows always match it.Rollout
The parser lives in
TableProPluginKit, which is embedded only in the app target. The MongoDB plugin links it dynamically and carries no copy, so the parse fix repairs export for every already-installed MongoDB plugin as soon as the app ships. No ABI bump, no plugin re-release needed for that half. The two plugin-side changes reach users with the nextplugin-mongodb-v*release.Tests
find/sort/skip/limit, dotted name kept whole, a name colliding with a database method, an escaped quote, a write method, whitespace before the argument list, three error cases, andgetSiblingDBstaying unsupported.buildExportQueryoutput back to afindon the same collection. That is the test that would have caught this.swiftlint lint --strictis clean on the changed files. The two violations it reports reproduce on the unmodified files atmainand sit in directories the repo config does not lint.