i writing middleware mongoose gets executed every find object using pre query hook.
postschema.pre('query', function(query, next) { // want access req.user object here query.populate('category'); next(); }); i want access req.user object inside pre every request made api server. how can pass object middleware?
is possible?
https://github.com/automattic/mongoose/issues/1931
i found above doesnt talk passing req object.
====================
edit after confusion question.
what trying accomplish req.user role , model name pass function query condition find. depending on user role , type of model accessed query condition change.
wrap middleware in middleware has access req.
something like, assuming express
router.verb('/some-route', function (req, res, next) { postschema.pre('query', function(query, next) { console.log(req); query.populate('category'); next(); }); }); edit - attach route want prehook for.
disclaimer - not tested.
Comments
Post a Comment