-
-
Notifications
You must be signed in to change notification settings - Fork 93
Open
Labels
Description
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 :)