M ZeeshanM
Convex Community17mo ago
20 replies
M Zeeshan

How to apply filter before pagination?

In the provided code, why are filter calls applied first to paginate the documents, and then the Predicate function is applied to those paginated documents?

What I need:
I want to first search the database, and then apply pagination to the filtered results. How can I modify the code to achieve this?

Provided Code:
    const results = await filter(ctx.db.query('skills'), (doc) => {
      return (
        doc.is_deleted === false &&
        (args.is_featured === undefined ||
          doc.is_featured === args.is_featured) &&
        (args.is_published === undefined ||
          doc.is_published === args.is_published) &&
        (!args.query || doc.title.includes(args.query))
      );
    }).paginate(args.paginationOpts);
Was this page helpful?