UNPKG

@tepez/mongo-cursor-pagination

Version:

Make it easy to return cursor-paginated results from a Mongo collection

16 lines (12 loc) 398 B
const base64url = require('base64-url'); const { EJSON } = require('bson'); /** * These will take a BSON object (an database result returned by the MongoDB library) and * encode/decode as a URL-safe string. */ module.exports.encode = function (obj) { return base64url.encode(EJSON.stringify(obj)); }; module.exports.decode = function (str) { return EJSON.parse(base64url.decode(str)); };