# cursor_paginate

> This module has been developed for mongoose cursor pagination using Mongo range queries or relevancy-based search results.

Latest version **1.0.3** (published 2019-08-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install cursor_paginate
pnpm add cursor_paginate
yarn add cursor_paginate
bun add cursor_paginate
```

## 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 | 1.0.3 |
| Published | 2019-08-13 |
| First published | 2019-07-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | techkartikey21 |
| Keywords | pagination, cursor pagination, cursor paginate, mongoose cursor paginate, mongoose pagination |

## Links

- npm: https://www.npmjs.com/package/cursor_paginate
- npm.io page: https://npm.io/package/cursor_paginate

## 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.0.3 (latest) — 2019-08-13
- 1.0.2 — 2019-08-13
- 1.0.1 — 2019-07-19
- 1.0.0 — 2019-07-19

## README

# cursor_paginate

This module has been developed for mongoose cursor pagination using Mongo range
queries or relevancy-based search results.


## Installation

```
npm install cursor_paginate --save
```

## Usage    

Define your mongoose schema and plug the cursor_paginate module.

```javascript
const paginate = require('cursor_paginate');

const testSchema = new mongoose.Schema({
  name: String,
  age: Number,
  mobile : Number,
  userId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'User',      // reference of user schema
  },
  categoryId: {
      type: mongoose.Schema.Types.ObjectId,
      ref: 'Category',  // reference of category schema
  }
});

testSchema.plugin(paginate);

const Test = mongoose.model('Test', testSchema);
```

## Model.paginate([params])

### Parameters

- [params] 

  - [previous] {String} - The value to start querying previous page.

  - [next] {String} - The value to start querying next page.

  - [limit] {Number} - The page size.

  - [fields] {Object} - Fields to query in the Mongo object format, e.g. {_id: 1, name :1} . The default is to query all fields.

  - [populate] - Name of the field or key you want to populate. e.g. [{ path: 'userId', select: {name:1 }}]
  'userId' is name of field, 'select' key gives selected fields from reference schema.


### Examples

- previous = req.query.previous || undefined
- next = req.query.next || undefined
- limit = 10
- fields = {id: 1, name :1} || { }
- populate = [{ path: 'userId', select: { name: 1 }}, { path: 'categoryId'}]

```javascript
test.paginate(
  previous,
  next,
  limit,
  fields,
  populate
)
.then((result) => {
 ...
})
```

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