A PubSub engine for graphql-subscriptions that uses MongoDB's capped collections and tailable cursors to broadcast subscription events across multiple server instances. Current stable version is 1.0.1, with peer dependencies on graphql-subscriptions (^1.0.0 || ^2.0.0) and mongodb (^5.3.0). It implements the PubSubEngine and AsyncIterator interfaces to integrate seamlessly with Apollo GraphQL subscriptions. Key differentiators: leverages MongoDB’s native pub/sub-like capped collection feature for persistence and scalability without additional message brokers. Suitable for stacks already using MongoDB.
npm install graphql-mongodb-subscriptionsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to create a MongodbPubSub instance with a connected MongoDB Db, and use asyncIterator and publish for a subscription topic.
Ensure MongoDB driver is v5.x compatible. For older drivers, version pinning may be required.
Always provide connectionDb via options. The database must already exist.
Test with your GraphQL server version. Consider using @graphql-yoga or Apollo Server 4 integration plugins.
Set channelOptions.size and channelOptions.max to appropriate values for your throughput.
Monitor collection size and adjust cap settings. Implement retry logic for missed events.
Drop the collection manually: db.collection('test').drop() and allow the library to recreate it.Use `import { MongodbPubSub } from 'graphql-mongodb-subscriptions';`Pass configuration object with connectionDb: db (a Db instance from MongoClient).
Set channelOptions.size to a valid number (bytes). Default is 1000000 (1MB).