Skip to content

After fetch hook? #262

@Floriferous

Description

@Floriferous

Maybe this is already possible with the current hooks, but I'm not entirely sure:

I'd like all of our limited/skipped mongo queries to also return the total count, without having to manually add this everywhere. This makes it very easy on the front-end to display counts, display a "load more" button (and stop showing it, once you've loaded everything), or simply display a table pagination widget with the total amount of pages.

I believe the place to do this would be in a after.fetch hook: here's roughly what I'd want it to do:

  const cursor = Users.find(query, options);

  const results = cursor.fetch();

  if (results?.length && options?.limit) {
    const count = cursor.count();
    results._queryCount = count;
  }

  return results;

If someone knows of another way to achieve this, or improve the implementation details (e.g. allow toggling this behavio on/off, depending on if you need the count), I'd be happy to learn about it :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions