# mongoose-page-query

> a small plugin just about forty codes that is used for the implemention of page query, it depends on mongoose and your environment support async functions.

Latest version **0.0.3** (published 2016-11-27) · 0 weekly downloads

## Install

```sh
npm install mongoose-page-query
pnpm add mongoose-page-query
yarn add mongoose-page-query
bun add mongoose-page-query
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2016-11-27 |
| First published | 2016-11-27 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+7 in 1 direct dependencies) |
| Install scripts | no |
| Author | sanrudongfeng |
| Maintainers | sanrudongfeng |

## Links

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

## Dependencies (1)

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

## Recent versions

- 0.0.3 (latest) — 2016-11-27
- 0.0.2 — 2016-11-27
- 0.0.1 — 2016-11-27

## README

# mongoose-page-query
a small plugin just about forty codes that is used for the implemention of page query,
it depends on mongoose and your environment support async functions.

## tables of contents
   1. [install](#install)
   2. [usage](#usage)
   3. [api](#api)
   4. [custom](#custom)

### install 
   <span id='install'></span>Install mongoose-page-query like this:
  `$ npm install --save-dev mongoose-page-query`
  before this you must install mongoose.
### usage
  <span id='usage'></span>use it as global plugin for every schema in mongoose when you connect databases.
  ````
     const mongoose = require('mongoose');
     const pageQuery = require('mongoose-page-query');
     mongoose.plugin(pageQuery);
   ```` 
  use it as a schema plugin like this.
  ````
    const mongoose = require('mongoose');
    const pageQuery = require('mongoose-page-query');
    const schema = new mongoose.Schema({ /* schema definition */ });
    schema.plugin(pageQuery); 
    const Model = mongoose.model('Model',  schema); // Model.pageQuery()
  ````
### api    
   <span id='api'></span>Model.pageQuery({page,row},condition,projection,option)you need use it in async functions.
   ````
     async function test() {
          //result {page: 1, row: 10, total: totalCount, rows: [data]}
         let result = await Model.pageQuery({page: 1,row: 10}, {}, {}, {});
         }  
   ````
   the four params must be specified. if you don not need ,just specify
       it as null.
                          
### custom 
   <span id='custom'></span>Set custom default options for all queries.this plugin has three default three params,
   lean:true,page:1,row:10.you can specific page and row param like this:
   ````  
      const mongoose = require('mongoose');
      const pageQuery = require('mongoose-page-query');
      pageQuery.defaultOption = {page: 1, row: 20};
   ````
   you can not set lean default value and just specify it in api option param,eg:
   ````
     async function test() {
                 let result = await Model.pageQuery({page: 1,row: 10}, {}, {}, {lean: false})
           }  
   ````

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