I am creating a store API.
I am trying to filter out the result using the field from req.query and select. Everything else works fine except the select.
Error: TypeError: result.select is not a function
if (field) {
const sortField = field.split(",").join(" ");
result = result.select(sortField);
}
Not sure why is the select not a function.
2
Answers
From the image, looks like
result
is a unresolved promise when you call theselect
.Also, there’s no
select
method for an array (witch I believe, is what you’re trying to filter out); instead you can usefilter
Try this:
Try with: