Smart segment pagination

Hello,
I have created a smart-segment and I’m trying to get pagination to work. The documentation shows how to set arbitrary limit to the number of results, but not how to implement proper pagination. How can I get the proper values I should set as $limit and $skip? My where function doesn’t seem to receive any useful arguments.

My project is using forest-express-mongoose 8.3.9

{
    name: "Segment name",
    where: () => {
      return model.find({
          isActive: true,
        },
        [
          {
            $project: { _id: true },
          },
          {
            $sort: { updatedAt: -1 },
          },
          {
            $limit: "???",
          },
          {
            $skip: "???",
          },
        ])
        .then((spots) => ({
          _id: { $in: spots.map(({ _id }) => _id).filter(Boolean) },
        }));
    },
  };
1 Like

Hello @louisremi ! :wave: Welcome to our community. :confetti_ball:

Clearly we are missing some documentation for forest-express-mongoose. You can still find some information on this topic here.

But in this example the limit is manually set. I’ll double check with a colleague.

Kind regards,
Morgan

I realized that I could simply write

{
    name: "Segment name",
    where: () => {
      return {
        isActive: true,
      };
    },
  };

And my segment would work equally well, with pagination and even search working as expected in Forest Admin. I’m wondering why the documentation is much more complex than that.

1 Like

Perfect @louisremi :pray:

I think the documentation is partially outdated. I will forward your feedback to the team.

Searching, filtering and pagination are automatically handled by Forest Admin. The only thing you have to return in your smart segment configuration, is the actual filter to scope your data.

Have a nice day.

Kind regards,
Morgan