Sync MongoDB collections via change streams into any database. Version 0.64.0, requires Redis (>=5.4.1) for state management and MongoDB driver (>=6.8.0). Provides initial scan with deterministic resumption and change stream event processing. Detects schema changes and emits events (e.g., 'schemaChange', 'processError'). Supports batch processing and configurable queue/scan options. Compared to alternatives, it is a lower-level library meant to be built upon, with companion libraries for MongoDB-to-MongoDB, Elasticsearch, and CrateDB sync. Uses debug for logging. ESM-only, ships TypeScript types.
npm install mongochangestreamNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to initialize sync with Redis and MongoDB, run an initial scan, process change stream events, and detect schema changes with event handling.
Implement a grace period or use the 'missingOplogEntry' utility to check if the change stream can resume from a stored token.
Add an index on the _id field if not already present, or consider custom sorting if needed.
Use named import: import { initSync } from 'mongochangestream'.Ensure Redis connection is properly configured. Run separate Redis instance or use ioredis with proper timeouts.
Change require('mongochangestream') to a dynamic import or set type: 'module' in package.json.Use import { initSync } from 'mongochangestream'.Ensure Redis client is created and passed: const redis = new Redis(); const sync = initSync(redis, coll);
Use the missingOplogEntry() helper to detect this and resync from scratch.