Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-6708

EJSON circular reference detection fails to account for .toJSON()

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: EJSON
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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

            Assignee:
            Unassigned Unassigned
            Reporter:
            anna.henningsen@mongodb.com Anna Henningsen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: