You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
bug
What is the current behavior?
Middleware "init" is a document middleware. But fires for the following hook where I have specifically added document: false.
In which above log its clear that the next is undefined & error is the document itself. This should not be the case for an error handler hook.
As per doc init hooks are synchronous and doesn't receive next as a parameter.
So I thought may be after findById the hook is being fired. So I changed the regexp where I'm adding the postHook in the schema, with the following.
This just says, for all which not starts with "i". And now the error is gone. So I'm thinking that for the init middleware the hook is being fired.
What is the expected behavior?
Middleware "init" is a document middleware. Should not fire when I'm adding hook for only query middleware..
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
nodejs@14.4.0
mongoose@5.9.28
mongodb@4.2.6
The text was updated successfully, but these errors were encountered:
jayadrathamondal
changed the title
init is a document middleware but being fired for the query middleware too.
init is a document middleware but being fired for the query middleware hook too.
Aug 11, 2020
jayadrathamondal
changed the title
init is a document middleware but being fired for the query middleware hook too.
Query middleware hook is being fired by "init"
Aug 11, 2020
Do you want to request a feature or report a bug?
bug
What is the current behavior?
Middleware "init" is a document middleware. But fires for the following hook where I have specifically added document: false.
If the current behavior is a bug, please provide the steps to reproduce.
Use the above hook for any schema and then do any query like following.
This will give error
TypeError: next is not a function
And see there is a console log in the postHook which gives following.
In which above log its clear that the next is undefined & error is the document itself. This should not be the case for an error handler hook.
As per doc init hooks are synchronous and doesn't receive next as a parameter.
So I thought may be after findById the hook is being fired. So I changed the regexp where I'm adding the postHook in the schema, with the following.
schema.post(/^!i\w+$/, { query: true, document: false }, postHook);
This just says, for all which not starts with "i". And now the error is gone. So I'm thinking that for the init middleware the hook is being fired.
What is the expected behavior?
Middleware "init" is a document middleware. Should not fire when I'm adding hook for only query middleware..
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
nodejs@14.4.0
mongoose@5.9.28
mongodb@4.2.6
The text was updated successfully, but these errors were encountered: