Skip to content

davidlondono/mongoose-paginate-cursor

Repository files navigation

mongoose-paginate-cursor

Build Status codecov npm License

Installation

npm install mongoose-paginate-cursor

Usage

// body parser
var mongoose = require('mongoose');
var mongoosePaginate = require('mongoose-paginate-cursor').default;

var ModelSchema = mongoose.Schema({
  title: String,
  count: Number
});

ModelSchema.plugin(mongoosePaginate,{
  // name: 'paged' // custom name of paginate function
})

var Model = mongoose.model('MyModel', ModelSchema);

var paged = await Model.paginate({
  sinceId, // from what value to get documents (default: null)
  maxId, // to what value to get documents (default: null)
  limit, //amount of documents to get on search (default: 1)
  select, //what values get on request
  where, // query to match the search
  keyPaginated, //key to paginate on document (ejm: 'count' ) (default: '_id')
  reverse, //tell the pagination to reverse the search
});

paged.objects // objects found
paged.nextCursor // the key value of the next cursor

.paginate() returns a promise, or can be used with a callback .paginate({},callback)

Features to have

  • Map: let the user map the documents
  • QueryMap: let the user map the query to add chain calls
  • Filter: filter documents and search more to reach the limit
  • beforeCursor: cursor for before request

Other notes

If you're not using Mongoose and instead using Mongo directly, consider using the vanilla version of this module: mongo-cursor-pagination.

License: MIT

About

Mongoose Plugin to paginate by cursor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published