0.2.0 • Published 7 years ago

mongul v0.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

mongul

NPM version build status Codecov

Paginates a MongoDB collection and add links to the next/prev page.

Install

npm install mongul --save

Examples

const express = require('express');
const app = express();
const paginate = require('mongul');

// without pagination
// GET http://localhost/items

app.get('/items', (req, res, next) => {
  collection
    .find({ owner: req.user }).toArray()
    .then(items => res.status(200).json(items))
}); 
  
// [{a:1, b:1}, {a:2, b:2}, {a:3, b:3}, {a:4, b:4}]

// with pagination
// GET http://localhost/items?start=0&limit=3

function index(req, res, next) {
  req.cursor = collection.find({ owner: req.user })
  next();
}

app.get('/items', index, paginate(), (req, res) => {
  res.status(200).json(req.page)
});

// { 
//   "items": [{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], 
//   "prev": null,
//   "next": "http://localhost/items?start=3&limit=3"
// }

License

MIT

TODO

http://tools.ietf.org/html/rfc5988#page-6

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago

0.0.0

8 years ago