Support non-ObjectId _id types in ClustersClient (fixes #217)#719
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR improves Data API autocomplete field references for MongoDB aggregation syntax, adds UI polish for index nodes, optimizes Monarch tokenization lookups, and refactors BSON _id parsing in the DocumentDB client.
Changes:
- Generate valid aggregation
referenceTextusing$getFieldwhen field segments aren’t safe identifiers, plus escaping for quotes/backslashes. - Cache and display index counts on the “Indexes” tree node, refreshing the node description when counts change.
- Refactor
_idparsing into a shared helper and optimize Monarch “cases” lookups via cachedSets.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/json/data-api/autocomplete/toFieldCompletionItems.ts | Builds aggregation-safe field references ($path vs $getField) and reuses escaping logic. |
| src/utils/json/data-api/autocomplete/toFieldCompletionItems.test.ts | Adds tests for $getField and escaping behavior in referenceText. |
| src/tree/documentdb/IndexesItem.ts | Caches index count and shows it as a tree item description, with refresh scheduling. |
| src/documentdb/shell/highlighting/monarchRunner.ts | Speeds up keyword/operator matching by converting arrays to cached Sets lazily. |
| src/documentdb/ClustersClient.ts | Introduces parseDocumentId helper and uses it for delete/point read filtering. |
| src/documentdb/ClusterSession.ts | Tightens typing around parsed IDs during in-memory deletion filtering. |
|
Thank you for this contribution, and an apology is in order. When we dug into this with your PR in hand, we found that the codebase already supported non-ObjectId What your PR did was genuinely valuable: it pointed our attention straight at this code path and pushed us to make it right. Building on your work, we:
So while the literal change here was not the final shape we shipped, your submission directly led to hardening this part of the codebase. Thank you for taking the time to file it and see it through. We really do appreciate it. |
Co-authored-by: venti <1308199824@qq.com>
- Extract parseDocumentId into a shared, unit-tested helper used by both ClustersClient and ClusterSession (removes duplicated logic). - EJSON.parse is treated as the driver's ground truth; it round-trips every _id type incl. embedded documents and arrays (field order preserved). - Keep the deterministic bare-24-hex -> ObjectId concession. - On unrecognized ids, log the (length-capped) value to ext.outputChannel and throw, instead of returning a raw string and risking the wrong document. - Add parseDocumentId unit tests.
81ccc29 to
7a60e0c
Compare
Fixes #217
Summary
Removes the hardcoded assumption that
_idis alwaysObjectIdinClustersClientandClusterSession. Documents with string_id, number_id, UUID_id, etc. can now be deleted, read, and upserted correctly.Changes
src/documentdb/utils/parseDocumentId.ts(new file):parseDocumentId()as a standalone utility -- usesEJSON.parseto handle all BSON types, falls back toObjectIdfor 24-char hex strings, and returns the raw string for any other valuesrc/documentdb/ClustersClient.ts:deleteDocuments()-- replaced inline ID parsing withparseDocumentId()pointRead()-- replaced inline ID parsing withparseDocumentId()upsertDocument()-- simplified ID parsing to useparseDocumentId()EJSONimport (now lives in the utility)src/documentdb/ClusterSession.ts:deleteDocuments()-- replaced inline ID parsing withparseDocumentId(); removedObjectIdimportBefore/After
{ "$oid": "..." }"my-key"42Testing
parseDocumentId.test.tswith 125 lines of coverage