Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/3zrv/mongoose-simple-pager
Lightweight pagination plugin for mongoose
https://github.com/3zrv/mongoose-simple-pager
mongoose mongoose-paginate mongoose-plugin nodejs
Last synced: 6 days ago
JSON representation
Lightweight pagination plugin for mongoose
- Host: GitHub
- URL: https://github.com/3zrv/mongoose-simple-pager
- Owner: 3zrv
- License: mit
- Created: 2023-01-02T11:34:34.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-05-13T15:51:12.000Z (over 1 year ago)
- Last Synced: 2024-10-18T14:54:35.307Z (30 days ago)
- Topics: mongoose, mongoose-paginate, mongoose-plugin, nodejs
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/mongoose-simple-pager
- Size: 687 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![npm version](https://badge.fury.io/js/mongoose-simple-pager.png)](https://badge.fury.io/js/mongoose-simple-pager)
[![Coverage Status](https://coveralls.io/repos/github/3zrv/mongoose-simple-pager/badge.svg?branch=master)](https://coveralls.io/github/3zrv/mongoose-simple-pager?branch=master)
![CI](https://img.shields.io/github/actions/workflow/status/0x3zra/mongoose-simple-pager/node.js.yml)
# mongoose-simple-pagerPagination plugin for [mongoose.js](http://mongoosejs.com/).
## Requirements
- [NodeJS](https://nodejs.org/en/) >= 6.0
## Installation
```bash
$ npm install mongoose-simple-pager
```## Example usage
```javascript
// userModel.js
import mongoose from "mongoose";
import paginate from "mongoose-simple-pager";const userSchema = mongoose.Schema({
firstName: {
type: String,
required: true,
},
lastName: {
type: String,
required: true,
},
userName: {
type: String,
required: true,
unique: true,
},
roles: [
{
type: mongoose.SchemaTypes.ObjectId,
ref: "roles",
},
],
});userSchema.plugin(paginate);
``````js
// controller.js
const User = mongoose.model("userModel");const options = {
limit: 5,
page: 1,
};return await User.paginate(options);
```### Output will be:
```json
{
"data": [
{
"obj1": {...}
},
{
"obj2": {...}
},
{
"obj3": {...}
},
{
"obj4": {...}
},
{
"obj5": {...}
}
],
"pagination": {
"total": 123
}
}
```### Adding a query and populate options
```javascript
const User = mongoose.model("userModel");const options = {
limit: 5,
page: 1,
};const query = {
$or: [
{
userName: {
$regex: "x",
$options: "i",
},
},
],
};return await User.paginate(options, "roles", query);
```## Todo
* Accept aggregate queries
* Migrate to typescript## Contributing
1. Fork it ( https://github.com/0x3zra/mongoose-simple-pager/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request## License
The MIT License (MIT)