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: Update ChangeStream hydration condition #12201

Merged
merged 1 commit into from Aug 8, 2022

Conversation

ramos-ph
Copy link
Contributor

@ramos-ph ramos-ph commented Aug 2, 2022

Summary

There is an issue when using a ChangeStream in a replica set, you'll get an undefined error when you try to call mongoose.disconnect():

await mongoose.connect(`mongodb://${host}:${port}/?replicaSet=${rset}`, {
  autoIndex: false,
});

const changeStream = mongoose.connection.watch(pipeline, {
  fullDocument: "updateLookup",
});
const stream = changeStream.on("change", (change) => {
  console.log(change);
});

await stream.close();
await mongoose.disconnect(); // `data.fullDocument` is undefined

The issue was introduced in one of the commits from versions 6.4.7 to 6.5.0, as stated in #12169. This PR fixes this by correctly addressing where the options are coming from.

Examples

Here's the result for the current version:
image

Here's the result for the fix:
image

Closes #12169

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

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

Why not just add if (data != null && data.fullDocument != null && ...) ?

lib/cursor/ChangeStream.js Outdated Show resolved Hide resolved
@ramos-ph ramos-ph requested a review from vkarpov15 August 3, 2022 22:10
@ramos-ph ramos-ph changed the title fix: Update option references in ChangeStream fix: Update data.fullDocument references in ChangeStream Aug 3, 2022
@ramos-ph ramos-ph changed the title fix: Update data.fullDocument references in ChangeStream fix: Update ChangeStream hydration condition Aug 3, 2022
@vnugent
Copy link

vnugent commented Aug 6, 2022

Hi,
when do you think we have this released?
I did a quick test. The issue still exists in 6.5.1

upgrading mongoose

-    "mongoose": "6.4.7",
+    "mongoose": "6.5.1",

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

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

I think this was also fixed in #12224, but we'll merge this one as well. Will ship a release with the fix within 24 hours 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In v6.5.0 mongoose.disconnect() causing Cannot read properties of undefined (reading 'fullDocument')
3 participants