-
Notifications
You must be signed in to change notification settings - Fork 156
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
Unable to see aggregation query result from contextFilter in outputFn #416
Comments
Just to be sure, can you verify |
@Zertz yes, outputFn is being called after aggregation query sets its result, but the result there is just of simple model.find query |
@Zertz Tried setting the result as |
Hi @Zertz, |
The result you are setting in I'm not sure exactly what you're trying to achieve but this should work: contextFilter: function (model, req, next) {
if (req.aggregationQuery) {
model.aggregate(req.aggregationQuery).then((result) => {
req.erm.aggregationResult = result;
next(model)
})
}
}
outputFn: (req, res, next) => {
const result = req.erm.aggregationResult;
const statusCode = req.erm.statusCode;
res.status(statusCode).json(result);
} |
@zerts the find query shouldn't run at all in the first place when aggregate query is present and executed. How can I stop that from happening? In my case, for a request, first aggregation query is executed, the result of which we are assigning to "req.erm.aggregationResult", then find query also executes for the same request. Is model we are passing to callback in "next(model)" executing the find query, if yes, how can that behaviour be changed? |
Perhaps this can help? |
Hi @florianholzapfel,
Although aggregation query executes and gives result in contextFilter, I am unable to access the same result in outputFn(req.erm.result). Here is the code snippet of contextFilter function:
Wherein, aggregationQuery has been added in request object in the preRead hook in this case.
Expectation:
The text was updated successfully, but these errors were encountered: