-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: SDAM
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.