feat(mongo): allow trailing comma in argument lists#127
Merged
Conversation
mongosh and JavaScript (since ES2017) accept a trailing comma at the end
of a function-call argument list. Production telemetry shows the shape
in the wild — e.g. `db.coll.find({…},).sort({…})` — pasted from editors
or generated by code formatters. The parser previously rejected the
trailing `,` with `expected ,, got ")"`, forcing the caller to fall back
to mongosh.
parseArguments now accepts a single trailing comma after a real argument
while still rejecting bare `(,)`, leading `(,a)`, and consecutive `(a,,)`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
rebelice
approved these changes
May 9, 2026
3 tasks
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
db.coll.find({…},).sort({…})— comes up in production telemetry from editors and code formatters; previously the parser rejected the trailing,withexpected ,, got ")".Behavior
db.coll.find({a: 1},)→ okdb.coll.find({}, {a: 1},)→ okdb.coll.find({a: 1},).sort({a: 1})→ ok (cursor chain unaffected)db.coll.find().limit(10,)→ ok (cursor-method args also tolerate it)db.coll.find(,)/db.coll.find(, {a: 1})/db.coll.find({a: 1},,)→ still errorTest plan
TestTrailingCommaInArgumentscovers all four success shapes including the exact wild case.TestArgumentListErrorsconfirms bare/leading/consecutive commas still fail.go test ./mongo/...passes (analysis, catalog, completion, parsertest).🤖 Generated with Claude Code