feat: support pretty() no-op and Int32/NumberInt string args#25
Merged
d-bytebase merged 5 commits intobytebase:mainfrom Mar 24, 2026
Merged
feat: support pretty() no-op and Int32/NumberInt string args#25d-bytebase merged 5 commits intobytebase:mainfrom
d-bytebase merged 5 commits intobytebase:mainfrom
Conversation
…080)
Fix 5 mongosh compatibility issues that caused unnecessary fallbacks:
- pretty(): treat as no-op cursor method (output already formatted)
- insert(): translate to insertOne/insertMany based on argument type
- count(): translate to countDocuments
- update(): translate to updateOne/updateMany based on multi option
- Int32("string")/NumberInt("string"): accept string arguments in parser
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Fix 2 mongosh compatibility issues that caused unnecessary fallbacks:
- pretty(): treat as no-op cursor method (output already formatted)
- Int32("string")/NumberInt("string"): accept string arguments in parser
Deprecated methods (insert, count, update) intentionally left as
unsupported to keep gomongo simple — they fall back to mongosh.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Move TestPrettyNoOp to collection_test.go (cursor method behavior) - Move TestInt32StringArg to bson_helpers_test.go (BSON helper behavior) - Delete compat_test.go - Add TODO comment on replace directive (remove after parser published) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Update github.com/bytebase/parser to include Int32/NumberInt string argument support (parser#64). Remove temporary local replace directive. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
rebelice
approved these changes
Mar 24, 2026
There was a problem hiding this comment.
Pull request overview
This PR improves mongosh compatibility in the gomongo translator by (1) treating pretty() as an accepted cursor method without changing behavior and (2) allowing Int32() / NumberInt() to accept numeric strings, aligned with existing Long / NumberLong behavior. It also bumps github.com/bytebase/parser to a version that includes the required grammar updates.
Changes:
- Add
pretty()handling as a no-op cursor method to avoid unsupported-method failures. - Extend
Int32()/NumberInt()helper conversion to accept string arguments. - Upgrade
github.com/bytebase/parserdependency to pick up grammar support.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/translator/visitor.go | Allows pretty() in cursor method chains as a no-op to prevent unsupported-method errors. |
| internal/translator/collection.go | Trailing whitespace/newline adjustment at EOF (no functional change). |
| internal/translator/bson_helpers.go | Adds string-literal support to convertInt32Helper for Int32("123") / NumberInt("123"). |
| internal/translator/bson_helpers_test.go | Adds an end-to-end test for string args (currently missing assertions for some inserted fields). |
| collection_test.go | Adds coverage for find().pretty(), find().sort().pretty(), and aggregate().pretty() chaining. |
| go.mod | Bumps github.com/bytebase/parser to a newer pseudo-version. |
| go.sum | Updates checksums for the upgraded parser dependency. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Assert NumberInt("456") stores as int32(456), not just no-error
- Assert NumberLong("1774250313") stores as int64(1774250313)
- Insert in reverse order in pretty() sort test so assertion is meaningful
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
d-bytebase
approved these changes
Mar 24, 2026
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.
Summary
pretty()as a no-op cursor method (output is already formatted viabson.MarshalExtJSONIndent)Int32()/NumberInt()helpers (e.g.,Int32("123")), matching existingLong/NumberLongbehaviorgithub.com/bytebase/parserto include grammar change (feat(mongodb): accept string arguments in Int32/NumberInt helpers parser#64)Context
Telemetry (BYT-9080) showed these as the most frequent gomongo compatibility failures causing unnecessary mongosh fallbacks. Deprecated methods (
insert,count,update) are intentionally left unsupported — they fall back to mongosh.Test plan
TestPrettyNoOpincollection_test.go— verifiesfind().pretty(),find().sort().pretty(),aggregate().pretty()TestInt32StringArginbson_helpers_test.go— verifiesInt32("123"),NumberInt("456"),NumberLong("1774250313")golangci-lintclean🤖 Generated with Claude Code