# mongoose-paginate-ts

> Typescript pagination plugin for mongoose

Latest version **1.3.2** (published 2025-10-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install mongoose-paginate-ts
pnpm add mongoose-paginate-ts
yarn add mongoose-paginate-ts
bun add mongoose-paginate-ts
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; high maintenance score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.3.2 |
| Published | 2025-10-08 |
| First published | 2020-05-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 16 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | IGLU |
| Maintainers | iglu-software |
| Keywords | mongoose, ts, typescript, paginate, pagination, paging, page, mongodb, nextpage, prevpage, paginator, cursor, starting, ending |

## Links

- npm: https://www.npmjs.com/package/mongoose-paginate-ts
- Repository: https://github.com/IGLU-Agency/mongoose-paginate-ts
- Homepage: https://github.com/IGLU-Agency/mongoose-paginate-ts#readme
- Issues: https://github.com/IGLU-Agency/mongoose-paginate-ts/issues
- npm.io page: https://npm.io/package/mongoose-paginate-ts

## Dependencies (1)

- [mongoose](https://npm.io/package/mongoose.md) ^8.19.1

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

- 1.3.2 (latest) — 2025-10-08
- 1.3.1 — 2023-06-27
- 1.3.0 — 2023-02-14
- 1.2.7 — 2022-07-15
- 1.2.6 — 2022-02-28
- 1.2.5 — 2022-02-28
- 1.2.4 — 2022-02-28
- 1.2.3 — 2022-02-08
- 1.2.2 — 2022-02-08
- 1.2.1 — 2022-02-04
- 1.2.0 — 2021-03-10
- 1.1.8 — 2021-03-10
- 1.1.7 — 2021-03-10
- 1.1.6 — 2021-03-10
- 1.1.5 — 2021-03-09
- … 19 more at https://npm.io/package/mongoose-paginate-ts/versions

## README

[![npm version](https://badge.fury.io/js/mongoose-paginate-ts.svg)](https://badge.fury.io/js/mongoose-paginate-ts)

# mongoose-paginate-ts

Typescript pagination (with page or cursor) plugin for [Mongoose](http://mongoosejs.com)

[![NPM](https://nodei.co/npm/mongoose-paginate-ts.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/mongoose-paginate-ts)

## Installation

```sh
npm install mongoose-paginate-ts
```

## Usage

Add plugin for a mongoose schema to inject a `paginate` method for pagination:

```ts
import { mongoosePagination, Pagination } from "mongoose-paginate-ts";
type User = mongoose.Document & {
  username: String,
  accounts: [mongoose.Types.ObjectId]
};
const userSchema = new Schema({
  username: String,
  accounts: [{ type: ObjectId, ref: "Account" }]
});
userSchema.plugin(mongoosePagination);
const User: Pagination<User> = mongoose.model<User, Pagination<User>>("User", userSchema);

//User.paginate()
```

### Model.paginate([options], [callback])

#### **Parameters**

- `[options]` {Object}
  - `[query]` {Object} - Query conditions. [Documentation](https://docs.mongodb.com/manual/tutorial/query-documents/)
  - `[select]` {Object | String} - Fields to return (by default returns all fields). [Documentation](http://mongoosejs.com/docs/api.html#query_Query-select)
  - `[sort]` {Object | String} - Sort order. [Documentation](http://mongoosejs.com/docs/api.html#query_Query-sort)
  - `[populate]` {Object | String} - Paths which should be populated with other documents. [Documentation](http://mongoosejs.com/docs/api.html#query_Query-populate)
  - `[page=1]` {Number}, 
  - `[limit=10]` {Number}, number of docs per page, default is 10
  - `[key=_id]` {String}, cursor id pagination 
  - `[startingAfter]` {String}, A cursor for use in pagination. startingAfter is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include startingAfter=obj_foo in order to fetch the next page of the list.
  - `[endingBefore]` {String}, A cursor for use in pagination. endingBefore is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, starting with obj_bar, your subsequent call can include endingBefore=obj_bar in order to fetch the previous page of the list.
  - `[forceCountFunction=false]` {Boolean} - Set this to true, if you need to support $geo queries.
  - `[lean=true]` {Boolean} - Set this to false, if you need to disable the lean.
- `[callback(err, result)]` - The callback is called once pagination results are retrieved or when an error has occurred

#### Result value

Promise fulfilled with an Pagination:

```ts
class PaginationModel {
  totalDocs: number | undefined;
  limit: number | undefined = 0;
  totalPages: number | undefined;
  page: number | undefined;
  pagingCounter: number | undefined;
  hasPrevPage: Boolean | undefined = false;
  hasNextPage: Boolean | undefined = false;
  prevPage: number | undefined;
  nextPage: number | undefined;
  hasMore: Boolean | undefined = false;
  docs: any[] = [];
}
```

### Examples

#### Paginate with

```ts
User.paginate({}).then((error: Error, result: any) => {
  // ...
});

var results = await User.paginate({})
```

#### More advanced example

```ts
var options = {
  query: {},
  select: "title date author",
  sort: { date: -1 },
  populate: "account",
  limit: 5
};

User.paginate(options).then((error: Error, result: any) => {
  // ...
});

var results = await User.paginate(options)
```

## License

[MIT](LICENSE)

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