Sync MongoDB collections to CrateDB and convert JSON schemas to SQL DDL. Version 0.60.0, actively maintained. Provides two main workflows: incremental sync using MongoDB change streams with initial scan, and schema conversion to CREATE TABLE statements. Key differentiators include support for schema change detection, custom value mapping (e.g., string truncation), and field omission. Ships TypeScript types. Requires peer dependencies ioredis (for change stream cursor persistence) and mongodb driver.
npm install mongo2crateNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to connect to MongoDB and CrateDB, initialize sync with Redis, create table from schema, and process change stream with initial scan.
Pass a Redis instance as first argument to initSync(). Example: initSync(new Redis({ keyPrefix: 'cratedb:' }), collection, crate(), options).Always call sync.getCollectionSchema(db) first and pass the returned schema to createTableFromSchema().
Provide a custom mapper function that slices strings as needed: mapper: (node) => typeof node.val === 'string' ? node.val.slice(0, 250) : node.val
Use sync.emitter.on('schemaChange', changeStream.stop) instead of calling changeStream.stop() directly.Always await MongoClient.connect() and pass the resolved db object to getCollectionSchema().
Ensure Redis client is properly instantiated: new Redis({ ... }) and passed as first argument.Call getCollectionSchema(db) first and pass its return value to createTableFromSchema().
Use import syntax and ensure project is configured as ESM (type: module in package.json) or use dynamic import.
Use a MongoDB replica set or use the 'watch' option with { fullDocument: 'updateLookup' } after ensuring replica set is enabled.