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

uniqueErrorPlugin breaks mongoose Model.bulkSave #84

Open
lexa274 opened this issue Oct 24, 2022 · 0 comments
Open

uniqueErrorPlugin breaks mongoose Model.bulkSave #84

lexa274 opened this issue Oct 24, 2022 · 0 comments

Comments

@lexa274
Copy link

lexa274 commented Oct 24, 2022

Hello,
I've encountered strange bug, when I added the mongoose-gridfs package to my project.

The uniqueErrorPlugin installs post hooks to every model I create. Everything works as expected when I use Model.save() method, but the Model.bulkSave() method starts to fail with this error:

TypeError: next is not a function
    at model.handleUniqueError (/mongoose-bulksave-hooks-test/node_modules/@lykmapipo/mongoose-common/lib/index.js:132:14)
    at next (/mongoose-bulksave-hooks-test/node_modules/kareem/index.js:238:35)
    at next (/mongoose-bulksave-hooks-test/node_modules/kareem/index.js:261:9)
    at next (/mongoose-bulksave-hooks-test/node_modules/kareem/index.js:230:16)
    at Kareem.execPost (/mongoose-bulksave-hooks-test/node_modules/kareem/index.js:266:3)
    at /mongoose-bulksave-hooks-test/node_modules/mongoose/lib/model.js:3747:29
    at new Promise (<anonymous>)
    at handleSuccessfulWrite (mongoose-bulksave-hooks-test/node_modules/mongoose/lib/model.js:3741:10)
    at mongoose-bulksave-hooks-test/node_modules/mongoose/lib/model.js:3716:15
    at Array.map (<anonymous>)

which is thrown by one of the hooks installed by the uniqueErrorPlugin.

I've created a repo with a test case reproducing the bug.
Using:
Node.js v18.10.0
NPM v8.19.2
mongoose v6.6.7
mongoose-gridfs v1.3.0

Do you have any tips on how to work around it, perhaps somehow not installing those hooks to every model?

Regards,
Alexandr

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

No branches or pull requests

1 participant