Repository navigation
fix(shell-bson-parser): do not treat own _bsontype field as a BSON value in toJSString COMPASS-11375 - #970
Merged
Conversation
…lue in toJSString
dudaschar
requested review from
alenakhineika
and
a balanced review from Copilot
November 13, 2026 10:18
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The guard breaks serialization of supported BSON 4 ObjectIds, and regression coverage is missing for plain documents with their own _bsontype properties.
2 open issues
What changed in this PR
This PR updates shell-bson-parser to serialize documents with their own _bsontype field as ordinary objects, preventing their fields from being interpolated as BSON constructor arguments.
Changes:
- Adds an own-property check before selecting BSON serialization.
- Keeps prototype-based BSON detection; regression tests are deferred to a follow-up PR.
| File | Description |
|---|---|
packages/shell-bson-parser/src/stringify.ts |
Excludes objects with an own _bsontype property from BSON-specific serialization. |
Review effort: Balanced
| const _bsontype = t === 'Object' && value._bsontype; | ||
| const _bsontype = | ||
| t === 'Object' && | ||
| !Object.prototype.hasOwnProperty.call(value, '_bsontype') && |
Collaborator
Author
There was a problem hiding this comment.
Tests are going to be added in a follow up PR
lerouxb
approved these changes
Nov 13, 2026
Merged
5 of 13 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.

Description
toJSStringdecides whether a value is a BSON type by readingvalue._bsontype. That also matches a plain object that has its own_bsontypefield, such as a document read from the server, so it was run through the BSON serializer and its field values were interpolated into the generated source as-is.BSON class instances define
_bsontypeon the prototype. This change treats an object with an own_bsontypeproperty as a plain object, so it is serialized like any other object. Real BSON values are serialized as before.Notes
Open Questions
Checklist