Nishil FalduN
Convex Community12mo ago
5 replies
Nishil Faldu

Combination of .paginate and getPage question

    const following = await ctx.db
      .query('follows')
      .withIndex('uniqueRelationship', (q) => q.eq('followerType', 'user')
      .eq('followerId', ctx.user._id))
      .paginate(paginationOpts);

    if (following.page.length === 0) {
      return {
        page: [],
        isDone: true,
        continueCursor: undefined
      };
    }

    const discussions = [];
    for (const follow of following.page) {
      const { page: discussionsPage } = await getPage(ctx, 
        {
          table: 'discussions', 
          index: 'byUserOrgUniversity', 
          startIndexKey: [follow.followeeId], 
          endIndexKey: [follow.followeeId], 
          absoluteMaxRows: 10
        });

      discussions.push(...discussionsPage);
    }


I have this piece of code where in I want to return discussion posts from a users' following - but I would want to return all pages of posts from a particular user and then move on to the next user i am following...how can that be done? I tried to read the blog and docs too, but I could not wrap my head around to actually doing it
Was this page helpful?