# mongoose-pagination-v2

> mongoose pagination

Latest version **0.0.4** (published 2024-04-30) · ISC license · 0 weekly downloads

## Install

```sh
npm install mongoose-pagination-v2
pnpm add mongoose-pagination-v2
yarn add mongoose-pagination-v2
bun add mongoose-pagination-v2
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2024-04-30 |
| First published | 2024-04-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | shazee257@gmail.com |
| Maintainers | shazee257 |
| Keywords | mongoose pagination |

## Links

- npm: https://www.npmjs.com/package/mongoose-pagination-v2
- Repository: https://github.com/shazee257/mongoose-pagination-package
- Homepage: https://github.com/shazee257/mongoose-pagination-package#readme
- Issues: https://github.com/shazee257/mongoose-pagination-package/issues
- npm.io page: https://npm.io/package/mongoose-pagination-v2

## Dependencies (4)

- [mongoose](https://npm.io/package/mongoose.md) ^8.3.3
- [mongoose-paginate-v2](https://npm.io/package/mongoose-paginate-v2.md) ^1.8.0
- [mongoose-aggregate-paginate-v2](https://npm.io/package/mongoose-aggregate-paginate-v2.md) ^1.0.7
- [@types/mongoose-aggregate-paginate-v2](https://npm.io/package/@types/mongoose-aggregate-paginate-v2.md) ^1.0.12

## 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

- 0.0.4 (latest) — 2024-04-30
- 0.0.3 — 2024-04-30
- 0.0.2 — 2024-04-30
- 0.0.1 — 2024-04-30

## README

## Mongoose Pagination & Aggregate

**Pagination Plugins:**
- You're utilizing two pagination plugins provided by the `mongoose-pagination-v2` package: `mongoosePlugin` and `mongooseAggregatePlugin`. These plugins enhance your mongoose schema with pagination capabilities for regular queries and aggregate queries respectively.

**Pagination Methods:**
- `getAggregatedPaginatedData`: This method is used to fetch paginated data from the MongoDB collection. It takes an object as an argument with properties like `model` (the mongoose model to query) and `query` (an array of query conditions). It returns paginated data based on the provided query conditions.
- `getPaginatedData`: Though not explicitly used in your code, it's likely a similar method provided by the pagination package for fetching paginated data from regular (non-aggregated) queries.

These methods and plugins streamline pagination handling in your application, making it easier to implement and manage pagination for mongoose queries and aggregations.


```javascript
const mongoose = require('mongoose');
const { mongoosePlugin, mongooseAggregatePlugin, getAggregatedPaginatedData, getPaginatedData } = require('mongoose-pagination-v2');

const express = require('express');
const app = express();

mongoose.connect(process.env.MONGO_URI)
.then(() => console.log('Connected to MongoDB'))
.catch((err) => console.log('Failed to connect to MongoDB', err));

// any key value allowed
const UserSchema = new mongoose.Schema({}, { strict: false });

UserSchema.plugin(mongoosePlugin);
UserSchema.plugin(mongooseAggregatePlugin);

const UserModel = mongoose.model('User', UserSchema);

app.get('/', async (req, res) => {
    // pagination without aggregate query
    // const data = await getPaginatedData({ model: UserModel, query: {}, page: 1, limit: 10 });

    // pagination with aggregate query
    const data = await getAggregatedPaginatedData({ model: UserModel, query: [], page: 1, limit: 10 });
    res.send(data);
});

app.listen(3000, () => {
    console.log('Server is running on http://localhost:3000');
});

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