
Product
Introducing Custom Pull Request Alert Comment Headers
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
mongoose-range-paginate
Advanced tools
An utility function to work with ranged pagination, way faster than using skip().
$ npm install mongoose-range-paginate
var paginate = require('mongoose-range-paginate')
...
// use any field name in your model, in this case we sort by 'timestamp'
var sortKey = 'timestamp'
// DESC because starts with a minus '-timestamp'
var sort = '-' + sortKey
function getQuery() {
return Posts.find()
.where({ tags: { $in ['foo', 'bar'] } })
}
paginate(getQuery(), { sort: sort, limit: 50 }).exec(function (err, docs) {
// first 50 docs ready
paginate(getQuery(), {
sort: sort,
startId: docs[49]._id,
startKey: docs[49][sortKey],
limit: 10
}).exec(function (err, docs) {
// next 10 docs ready
})
})
var paginate = require('mongoose-range-paginate')
...
router.get('/list', function *() {
var query = Posts.find()
.where({ tags: { $in ['koajs', 'yield'] } })
.where({ published: true })
.where({ author: 'Kilian' })
// force sorting, newest first
this.query.sort = '-timestamp'
// pass limit, startId and startKey on query string
paginate(query, this.query)
this.type = 'json'
this.body = query.lean().stream().pipe(stringify())
})
paginate(query, opts)
String) mongoose sort criteria, supports ASC and DESC with the "-" prefix.Number: defaults to 10) limits the number of documents.String) id of the last document of your last result set, next result set will start with the document next to this.String) the value of the sort field of the last document of your result set, next result set will start with the document next to this.Be sure you have MongoDb up and running locally, then run
$ npm test
This software is released under the MIT license cited below.
Copyright (c) 2014 Kilian Ciuffolo, me@nailik.org. All Rights Reserved.
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the 'Software'), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
FAQs
Fast range paginator for mongoose
We found that mongoose-range-paginate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.

Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.

Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.