> For the complete documentation index, see [llms.txt](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/extra-module-5-advanced-querying/pagination/find-and-count.md).

# Find and count

Bring the entities together with their total count.

We already have the pagination functionality. It would be interesting if we could, apart from bringing the **paginated result**, also bring the **total item count**. With this, it would be possible to determine if there is a next page or if the search is already at the end, for example. To achieve this is very simple. We just need to go back to the <mark style="color:blue;">`findAll()`</mark> method in the <mark style="color:blue;">`ProductsService`</mark> and replace the repository's <mark style="color:blue;">`find()`</mark> call with <mark style="color:blue;">`findAndCount()`</mark>.&#x20;

With this, we can already see the elements of the page and the total count. However, the result is a bit messy, don't you think? It's all mixed up in a single array. Luckily, to solve this is too very simple. If you hover the cursor over the <mark style="color:blue;">`findAndCount()`</mark> method, you'll notice that it returns an array with two elements. We can then use destructuring to extract them into their own fields:

```typescript
const [data, count] = await this.productsRepository.findAndCount({
  // Pagination data
});

return { data, count };
```

<mark style="color:green;">**Commit**</mark> - Incrementing pagination with total count
