# @leonardosarmentocastro/pagination

> mongoose pagination

Latest version **2.4.5** (published 2024-06-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install @leonardosarmentocastro/pagination
pnpm add @leonardosarmentocastro/pagination
yarn add @leonardosarmentocastro/pagination
bun add @leonardosarmentocastro/pagination
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.4.5 |
| Published | 2024-06-24 |
| First published | 2021-05-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 6.6 KB |
| Known vulnerabilities | 0 (+5 in 1 direct dependencies) |
| Install scripts | no |
| Author | leonardosarmentocastro |
| Keywords | mongoose, pagination |

## Links

- npm: https://www.npmjs.com/package/@leonardosarmentocastro/pagination
- npm.io page: https://npm.io/package/@leonardosarmentocastro/pagination

## Dependencies (4)

- [mongoose](https://npm.io/package/mongoose.md) 6.5.0
- [validator](https://npm.io/package/validator.md) ^13.6.0
- [@leonardosarmentocastro/i18n](https://npm.io/package/@leonardosarmentocastro/i18n.md) ^2.0.0
- [@leonardosarmentocastro/database](https://npm.io/package/@leonardosarmentocastro/database.md) ^2.4.5

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 2.4.5 (latest) — 2024-06-24
- 2.0.0 — 2023-12-07
- 1.4.27 — 2023-04-30
- 1.4.26 — 2023-04-24
- 1.4.25 — 2023-04-20
- 1.4.24 — 2023-04-20
- 1.4.0 — 2023-02-01
- 1.3.1 — 2022-08-30
- 1.0.1 — 2022-08-07
- 1.0.0 — 2022-08-04
- 0.0.2 — 2021-05-05
- 0.0.1 — 2021-05-04

## README

# pagination

mongoose pagination (mongoose plugin + express middleware)

## How it works?

Create a Mongoose model and plug in the pagination schema:

```js
const Mongoose = require('mongoose');
const { paginationPlugin } = require('@leonardosarmentocastro/pagination');

const schema = new Mongoose.Schema({ name: String, price: Number });
schema.plugin(paginationPlugin);
const model = Mongoose.model('Product', schema);
```

Perform queries sending relevant metadata, such as `conditions` (criterias), `limit`, `page` and `sorting`:

```js
const {
  PRODUCTS,
  PRODUCT1, PRODUCT2, PRODUCT3,
  PRODUCT4, PRODUCT5, PRODUCT6,
  PRODUCT7, PRODUCT8, PRODUCT9,
  PRODUCT10
} = require('../../__fixtures__');

(async () => {
  for (const product of PRODUCTS) {
    await model.create(product);
  }

  const pagination = { conditions: {},  limit: 5,  page: 2, sort: { price: 'desc' } };
  const results = await model.paginate(pagination);
  console.log(results);
  /** {
    docs: [ PRODUCT5, PRODUCT4, PRODUCT3, PRODUCT2, PRODUCT1 ],
    hasNextPage: false,
    hasPreviousPage: true,
    nextPage: null,
    previousPage: 1,
    totalCount: 10,
    totalPages: 2,
  } **/
})();
```

---
_Source: https://npm.io/package/@leonardosarmentocastro/pagination · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
