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

Support document middleware #395

Open
AdamGerthel opened this issue Nov 14, 2020 · 4 comments
Open

Support document middleware #395

AdamGerthel opened this issue Nov 14, 2020 · 4 comments

Comments

@AdamGerthel
Copy link

Feature request

Support document middleware

Background

AFAIK, document middleware, such as mongoose pre-save hooks, are not supported. I'm assuming that this is because feathers-mongoose uses queries such as findOneAndUpdate() rather than loading the document and then saving it (see https://mongoosejs.com/docs/middleware.html#notes).

As suggested in other issues, it's possible, and often recommended, to utilise Feathers service hooks instead. However, there are use cases when that option is not very fitting. An example is when you are re-using a single schema in several other schemas. Perhaps even nested on different levels in different models.

In such a use case, using service hooks would be very messy compared to a single, all-encompassing Mongoose pre validate/save/remove hook.

@daffl
Copy link
Member

daffl commented Nov 14, 2020

This should work already as long as you set the lean option to false.

@AdamGerthel
Copy link
Author

@daffl I've read that too somewhere, but it doesn't! I've tried every possible way/setting/option.

@daffl
Copy link
Member

daffl commented Nov 17, 2020

Ideally we'd need an example of what isn't working as expected then.

@AdamGerthel
Copy link
Author

Yep, I totally get that. Will see if I get time to throw together a small repro repo.

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

2 participants