This repo shows how to watch changes in a collection with the ChangeStream API.
It consists of a mongo database with two nodes in replicaset, a watcher container that prints all documents inserted into the "logs" collection, and a generator container that generate random messages and make bulk inserts into the same "logs" collection. The generator container can be started with multiple replicas.
- Docker and Docker compose installed
- A copy of Nats Streaming UI
- First you need to start mongo in replicaset. Start the nodes:
docker-compose up -d mongo0 mongo1
- Connect to one nodo and set the configuration:
docker exec -it mongo0 mongo
- Once inside Mongo shell console, set the config and initiate the replicaset:
config={"_id":"rs0","members":[{"_id":0,"host":"mongo0:27017"},{"_id":1,"host":"mongo1:27017"}]}
rs.initiate()
git clone --depth=1 [email protected]:united-travel-tickets/common/nats-streaming-ui.git
Start the ChangeStream watcher container:
docker-compose up mongo-watcher-socket
You can start multiple generators with the scale command:
docker scale nats-generator=10
Set scale to 0 if you want to stop inserting messages into the logs collection