(mongodb-cdc)= # Relay MongoDB Change Stream into CrateDB :::{rubric} What's inside ::: Documentation and [example program][mongodb_cdc_cratedb.py] how to relay data from MongoDB into [CrateDB], using [MongoDB Change Streams]. > Change streams allow applications to access real-time data changes without the prior > complexity and risk of manually tailing the oplog. Applications can use change streams > to subscribe to all data changes on a single collection, a database, or an entire > deployment, and immediately react to them. > > - [MongoDB Change Streams] > - [Monitor Data with Change Streams] :::{note} `commons-codec` includes `MongoDBFullLoadTranslator` and `MongoDBCDCTranslator`. This document and example program is exclusively about the latter. ::: ## Prerequisites Start services CrateDB and MongoDB. :::{rubric} Start CrateDB ::: ```shell docker run --rm --name=cratedb --publish=4200:4200 --env=CRATE_HEAP_SIZE=2g \ docker.io/crate:latest '-Cdiscovery.type=single-node' ``` :::{rubric} Start MongoDB ::: Please note that change streams are only available for replica sets and sharded clusters, so let's define a replica set by using the `--replSet rs-testdrive` option when starting the MongoDB server. ```shell docker run --rm --name=mongodb --publish=27017:27017 \ docker.io/mongo:8 mongod --replSet rs-testdrive ``` Now, initialize the replica set, by using the `mongosh` command to invoke the `rs.initiate()` operation. ```shell export MONGODB_URL="mongodb://localhost/" docker run -i --rm --network=host docker.io/mongo:8 mongosh ${MONGODB_URL} <