🔥 a api friendly mongoose pagination tool
npm install --save mongoose-sex-page
const Dummy = mongoose.model('Dummy', DummySchema)
const P = require('mongoose-sex-page')
P(Dummy)
.page(1)
.size(20)
.exec()
.then((result) => {
})
P(Dummy)
.find({dummy: dummy})
.page(1)
.size(20)
.display(8)
.simple(true)
.exec()
.then((result) => {
})
P().config({
page_name: 'page',
size_name: 'size',
size: 20,
display: 10,
// only return records
light: true
})
// for such a request /users?size=20&page=1 /news?size=20&page=1
P().config({
page_name: 'page',
size_name: 'size',
size: 20
})
// then
P(Dummy)
.find({dummy: dummy})
.inject(req.query)
.exec()
.then((result) => {
})
{
"page": 1,
"size": 5,
"total": 100,
"records": [{
"name": "Test1",
"age": 1
}, {
"name": "Test2",
"age": 2
}, {
"name": "Test3",
"age": 3
}, {
"name": "Test4",
"age": 4
}, {
"name": "Test5",
"age": 5
}],
"pages": 20,
"display": [1, 2, 3, 4, 5, 6]
}
npm test