A library that provides Relay-compatible cursor-based pagination for MongoDB cursors, mongoose queries, and aggregations. Version 2.1.0 is the latest stable release, with a simple API similar to graphql-relay's connectionFromArray. It automatically applies skip/limit to the cursor to fetch only necessary documents. Differentiators: supports both native MongoDB driver and mongoose, optional mapper function, and does not require pre-sorting or building edges array in memory.
npm install relay-mongodb-connectionNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to use connectionFromMongoCursor with graphql-relay's connectionArgs and connectionDefinitions.
Ensure you pass the result of .find() or .aggregate() directly, not a thenable.
Add a mapper function: connectionFromMongoCursor(cursor, args, doc => ({ ...doc, _id: doc.customId }))Use import statements or ensure your bundler handles ESM.
Use import connectionFromMongoCursor from 'relay-mongodb-connection' or use require('relay-mongodb-connection').defaultAwait the promise before calling connectionFromMongoCursor
Spread connectionArgs in the field definition: args: { ...connectionArgs }