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

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

Closed
2 tasks done
vnugent opened this issue Jul 29, 2022 · 1 comment · Fixed by #12201
Closed
2 tasks done

Comments

@vnugent
Copy link

vnugent commented Jul 29, 2022

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Mongoose version

6.5

Node.js version

16.15

MongoDB server version

mongo:5 from official Docker repo

Description

I have a unit test that was working fine in v6.4.7. In 6.5.0 change stream throws an exception when mongoose.disconnect() is called at the of the test.

data is undefined here
https://github.com/Automattic/mongoose/blob/6.5/lib/cursor/ChangeStream.js#L57

Home/git/openbeta/openbeta-graphql/node_modules/mongodb/lib/utils.js:419
                    throw error;
                    ^

TypeError: Cannot read properties of undefined (reading 'fullDocument')
    at ChangeStream.<anonymous> (/Home/git/openbeta/openbeta-graphql/node_modules/mongoose/lib/cursor/ChangeStream.js:57:22)
    at ChangeStream.emit (node:events:539:35)
    at ChangeStreamCursor.<anonymous> (/Home/git/openbeta/openbeta-graphql/node_modules/mongodb/src/change_stream.ts:817:46)
    at ChangeStreamCursor.emit (node:events:527:28)
    at /Home/git/openbeta/openbeta-graphql/node_modules/mongodb/src/cursor/abstract_cursor.ts:823:18
    at /Home/git/openbeta/openbeta-graphql/node_modules/mongodb/src/utils.ts:535:5
    at completeEndSession (/Home/git/openbeta/openbeta-graphql/node_modules/mongodb/src/sessions.ts:283:9)
    at /Home/git/openbeta/openbeta-graphql/node_modules/mongodb/src/sessions.ts:297:7
    at maybePromise (/Home/git/openbeta/openbeta-graphql/node_modules/mongodb/src/utils.ts:520:3)
    at ClientSession.endSession (/Home/git/openbeta/openbeta-graphql/node_modules/mongodb/src/sessions.ts:258:24)
e


Steps to Reproduce

Important: Test requires a replica set.

await mongoose.connect(
      `mongodb://${user}:${pass}@${server}/testdb?authSource=admin&readPreference=primary&ssl=false&replicaSet=${rsName}`,
      { autoIndex: false }
    )

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

await stream.close() // not helping
await mongoose.disconnect() 

Expected Behavior

No undefined exception like in v6.4.7

@vnugent vnugent changed the title in v6.5.0 mongoose.disconnect() causing Cannot read properties of undefined (reading 'fullDocument') In v6.5.0 mongoose.disconnect() causing Cannot read properties of undefined (reading 'fullDocument') Jul 29, 2022
@ramos-ph
Copy link
Contributor

ramos-ph commented Aug 1, 2022

Hey, I've tested a little bit and turns out that data was also undefined in previous working version, so I made a few changes in ChangeStream.

I've created this branch to try and solve the problem, let me know if it is from any help!

https://github.com/ramos-ph/mongoose/tree/fix/12169

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 a pull request may close this issue.

2 participants