noob saibotN
Convex Community14mo ago
7 replies
noob saibot

Help me better understand paginated queries

I'm having trouble running a paginated query in server using the filter from the convex-helpers library when, in client, I give a small value to initialNumItems.

I have 2 tables:

table campaigns
 _id,
 campaign_name

table members
_id,
campaign_id,
user_id

Now I want to find all the campaigns where "user_id" is part of, using a paginated query. So I write this function:
args: {
 user_id: v.id("members),
 paginationOpts: paginationOptsValidator,
},
handler: async (ctx, { user_id, paginationOpts }) => {
  // first I find all records from table "members" for user "user_id"
  const members = await ctx.db.query("members").withIndex("by_user_id", ...);

  // then paginated query of campaigns using the 'filter' method from `convex-helpers`
  const result = await filter(ctx.db.query("campaigns"), (cp) => members.some((mem) => mem.campaign_id === cp._id)).paginate(paginationOpts)
...
}


The last query will return data only if I give a bigger value to initialNumItems: with value 3 it returns 2 records, but with 10 then it find the 3 records I'm expecting.

It seems to me that the filtering I'm applying is messing up the cursor and perhaps the first record found by the pagination is beyond the initial cursor?
Was this page helpful?