1.0.1 • Published 8 years ago
mongoose-anchor-pagination v1.0.1
mongoose-anchor-pagination
Mongoose.js Document Query Pagination with anchors
Pagination plugin for Mongoose
Requirements
Mongoose >= 4.0
Installation
npm mongoose-anchor-pagination
Usage
Add plugin to a schema:
var mongoose = require('mongoose');
var mongooseAnchorPaginate = require('mongoose-anchor-pagination');
var schema = new mongoose.Schema({ /* schema definition */ });
schema.plugin(mongooseAnchorPaginate);
Model.find(query, fields, options, callback)
Parameters
[options]
{Object}[next_anchor]
{String}[prev_anchor]
{String}[sort=_id]
{Object | String} - Sort order. Documentation[limit=10]
{Number}
Examples
Sort all documents, skip with count <= 3 and return 10 documents
Model.find({}}, null, { 'sort': 'count' 'next_anchor': '3', 'limit': 10}, function(err, result) {
// All docs with count > 3
});
Or you can do the same with ObjectId:
Model.find({}}, null, {'next_anchor': '578cba6e33e462dcaad82df8'}, function(err, result) {
// All docs with _id > 578cba6e33e462dcaad82df8
});
With promise:
Model.find({}}, null, { 'sort': 'count' 'next_anchor': '3', 'limit': 10}).then(function(result) {
// ...
});
With populate:
Model.find({}}, null, { 'sort': 'count' 'next_anchor': '3', 'limit': 10}).populate('fruits').then(function(result) {
// ...
});
Tests
npm install
npm test