I am building an application, where I need to intercept all queries that are being made against the database for a particular model. Depending on certain states (executing user, etc.) I need to modify the query and add additional conditions to it. Is there already a way of doing something like that in mongoose? I figured middleware would be a good place to start, but it seems middleware only provides interfaces to intercept CRUD operations.
Why does middleware only allow intercepting CRUD operations, but not query operations?
I am quite new to mongoDB and mongoose, so I would really appreciate some help from more experienced developers with this problem.
I implemented a prototype, where I override the model's find function to allow for intercepting the query. Are there any plans to implement such a feature in mongoose in the near future? Do you see any architectural problems for my application in using this approach?
Thanks for your help!