A Relay-style cursor pagination tool for mongoose schema. Designed to work with GraphQL.
Quick view
// User.js
import mongoose, { Schema } from 'mongoose';
import { honeypager } from 'honey-pager';
const schema = Schema({
firstName: { type: String },
lastName: { type: String },
email: { type: String }
});
schema.plugin(honeypager);
export default schema;
// server.js
import express from 'express';
import User from './User';
let app = express();
// ...
app.get('/users', (req, res) => {
const result = User.paginateResult();
res.status(200).json(result);
});
This will gives you the following response:
{
"totalCount": 10,
"edges": [
{
"cursor": "...",
"node": {
"firstName": "John",
"lastName": "Doe",
"email": "jdoe@test.com"
}
},
...
],
"pageInfo": {
"startCursor": "...",
"endCursor": "...",
"hasNextPage": false,
"hasPreviousPage": false
}
}
Made with