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

Make TopologyDescription's serverDescriptions Map JSON stringifyable

    • 2
    • 0
    • Not Needed
    • v5.x
    • 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?

      How are you using Mongo? What version of the server and driver are you using?

      The Node.js driver uses an ES Map to store serverDescriptions however when printing out topology descriptions the server Map is lost if the event is stringified with JSON.

      When printing out server selection errors as JSON, the topology's servers map appears as an empty object. This creates confusion when debugging and we should provide a way to properly JSON stringify the servers map.

      What is the feature/improvement you would like?

      We should consider adding a toJSON hook to the Map instance we create that can convert the Map to an object or something otherwise printable when JSON-ified.

      What use case would this feature/improvement enable?

      Printing SDAM events that have been JSON.stringify -ed.

      Questions

      • Should we subclass Map and add a toJSON hook?
        • Yes to subclassing- we want the server’s Map to be the one that’s able to turn into a printable JSON string
      • Should we add toJSON hooks to our SDAM events that convert the Map?
        • No
      • This issue would be less prevalent with logging, however, event handler + JSON.stringify + console.log will likely still be commonplace. Does this change have API guarantees?
        • No public API guarantee

      AC

      • Make `TopologyDescription`'s `servers` property non-empty when the object is JSON stringified
        • Create a plain object where all keys in the Map map to all values
      • Decide whether plain JSON stringification is sufficient or if we need to use EJSON.stringify
      • Decide which branches, if any, we want to port it to
        • Backport to 5.x, the backport should be straightforward.

            Assignee:
            bailey.pearson@mongodb.com Bailey Pearson
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Aditi Khare
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: