Cursor-based pagination for MongoDB collections, written in TypeScript. v1.10.0 (stable, actively maintained) follows the Relay cursor connection spec, providing cursor-based pagination as a more stable alternative to offset-based pagination (which can miss/duplicate items when data changes between pages). The package ships TypeScript types and offers two main functions: `findPaginated` for simple queries and `aggregatePaginated` for aggregation pipelines. Based on mongo-cursor-pagination but with a cleaner API that returns standard pagination metadata (hasNextPage, hasPreviousPage, startCursor, endCursor). Peer dependency on mongodb driver 6.x.
npm install mongodb-cursor-paginationNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates cursor-based pagination using findPaginated with forward pagination (first + after) and TypeScript types.
Replace require('mongodb-cursor-pagination') with import { findPaginated, aggregatePaginated } from 'mongodb-cursor-pagination'Update mongodb peer dependency to ^6.0.0
For aggregation pipelines, use aggregatePaginated(collection, pipeline, options)
Pass a plain filter object to the 'query' option. For complex filtering, consider using aggregatePaginated with $match.
Use the provided cursor values directly – do not decode them manually.
npm install mongodb-cursor-pagination && use import syntax. If using require, migrate to ESM or use dynamic import (import()).
Change to: import { findPaginated } from 'mongodb-cursor-pagination'Use the cursor values from previous result.pageInfo.endCursor or startCursor directly.