Skip to content

Using populate with pagination #97

Answered by pkester
buzzcore asked this question in Q&A
Discussion options

You must be logged in to vote

Hello, I am also new to this project and the entire ecosystem but here is how I did it based at the controller level. Not sure about best practice, maybe someone else with more experience can chime in.

const getProjects = catchAsync(async (req, res) => {
  const filter = pick(req.query, ['lastname', 'city']);
  const options = pick(req.query, ['sortBy', 'limit', 'page']);
  options.populate = 'user'; 
  const result = await projectService.queryProjects(filter, options);
  res.send(result);
});

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by hagopj13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants