Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NODE-5530): make topology descriptions JSON stringifiable #4070

Merged
merged 6 commits into from
Apr 11, 2024

Conversation

baileympearson
Copy link
Contributor

@baileympearson baileympearson commented Apr 4, 2024

Description

What is changing?

This is basically entirely invisible to users. However, the TopologyDescription is a field on MongoServerSelectionErrors, so if a user is calling JSON.stringify on their errors, they will now see the servers field in the output instead of an empty object.

Is there new documentation needed for these changes?

No.

What is the motivation for this change?

Release Highlight

TopologyDescription now properly stringifies itself to JSON

The TopologyDescription class is exposed by the driver in server selection errors and topology monitoring events to provide insight into the driver's current representation of the server's topology and to aid in debugging. However, the TopologyDescription uses Maps internally, which get serialized to {} when JSON stringified. We recommend using Node's util.inspect() helper to print topology descriptions because inspect properly handles all JS types and all types we use in the driver. However, if JSON must be used, the TopologyDescription now provides a custom toJSON() hook:

client.on('topologyDescriptionChanged', ({ newDescription }) => {
   // recommended!
	console.log('topology description changed', inspect(newDescription, { depth: Infinity, colors: true }))

    // now properly prints the entire topology description
	console.log('topology description changed', JSON.stringify(newDescription))
});

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@baileympearson baileympearson marked this pull request as ready for review April 5, 2024 16:52
@nbbeeken nbbeeken changed the title fix(node-5530): make topology descriptions JSON stringifiable fix(NODE-5530): make topology descriptions JSON stringifiable Apr 5, 2024
@aditi-khare-mongoDB aditi-khare-mongoDB self-assigned this Apr 8, 2024
@aditi-khare-mongoDB aditi-khare-mongoDB added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Apr 8, 2024
@aditi-khare-mongoDB aditi-khare-mongoDB added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Apr 8, 2024
@W-A-James W-A-James self-requested a review April 9, 2024 03:13
Copy link
Contributor

@W-A-James W-A-James left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but can we have a short release note since this is public facing

@aditi-khare-mongoDB aditi-khare-mongoDB merged commit 3a0e011 into mongodb:main Apr 11, 2024
17 of 26 checks passed
baileympearson added a commit to baileympearson/node-mongodb-native that referenced this pull request Apr 11, 2024
…b#4070)

Co-authored-by: Aditi Khare <106987683+aditi-khare-mongoDB@users.noreply.github.com>
baileympearson added a commit to baileympearson/node-mongodb-native that referenced this pull request Apr 15, 2024
…b#4070)

Co-authored-by: Aditi Khare <106987683+aditi-khare-mongoDB@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants