-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: EJSON
const { EJSON } = require('bson'); const a = { toJSON() { return 42; } }; console.log(EJSON.serialize(a)); // works a.a = a; console.log(EJSON.serialize(a)); // throws, but should return same result as above
Use Case
As a... bson library user
I want... standardized JS functionality to work
So that... the EJSON methods are consistent with standard JSON behavior, and the BSON library doesn't attempt to traverse potentially large and complex objects when it shouldn't
User Experience
Serializing/stringifying an object that has toJSON method should not fail because of circularity issues.
Dependencies
This came up in conversation about the JSON stringification behavior of mongosh, and how it would be convenient to be able to use toJSON to throw a better exception when a user attempts to serialize/stringify a cursor using EJSON.stringify().
Risks/Unknowns
- What could go wrong while implementing this change? (e.g., performance, inadvertent behavioral changes in adjacent functionality, existing tech debt, etc)
- Is there an opportunity for better cross-driver alignment or testing in this area?
- Is there an opportunity to improve existing documentation on this subject?
Acceptance Criteria
Implementation Requirements
- functional reqs, potential snafus to avoid, performance targets, etc
Testing Requirements
- unit test, spec test sync, etc
Documentation Requirements
- DOCSP ticket, API docs, etc
Follow Up Requirements
- additional tickets to file, required releases, etc
- if node behavior differs/will differ from other drivers, confirm with dbx devs what standard to aim for and what plan, if any, exists to reconcile the diverging behavior moving forward
- is related to
-
MONGOSH-2002 Throw for EJSON.serialize(cursor)
-
- Closed
-