Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mongoose-efficient-pagination

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongoose-efficient-pagination

A configurable mongoose pagination plugin that uses objectIds rather than skip

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

mongoose-efficient-pagination

Build Status Coverage Status Dependency Status npm version

How it works

Use Case

Installation

npm install --save mongoose-efficient-pagination

API Reference

mongooseEfficientPagination

Using skip is not efficient for large data sets. Rather, we can achieve pagination by sorting by _id then telling mongo to use that _id as a starting point when returning the next page of records.

Example

// configure mongoose
var mongoose = require('mongoose');
var paginator = require('mongoose-efficient-pagination');

// optionally globally configure the default perPage value.
// this can be overridden in the paginate function itself.
paginator.perPage = 25;

Use it with a model...

var Customer = mongoose.model('Customer');
var sortOrder = -1;
var perPage = 10;
var startAfter = '52c1190207d5dbccda00000f'; // this value should be passed from your previous result set.

Customer.find({
    status: 'active'
})
.sort({
    createdAt: sortOrder, // this is up to you, sort by a field. I chose createdAt for this example.
})
.paginate(perPage, startAfter)
.exec();

mongooseEfficientPagination~paginator(perPage, [nextID]) ⇒

Can be called from the mongoose model prototype providing an easy way to paginate the result set of a query.

Kind: inner method of mongooseEfficientPagination
Returns: this

ParamTypeDefaultDescription
perPagenumber20number of records per page
[nextID]ObjectId(null)the id of the document which you will be starting after

Keywords

FAQs

Package last updated on 09 Jan 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc