/redpanda:connect-cdc-mongodbfrom redpanda
Streams change data capture from MongoDB into Redpanda or Kafka using Redpanda Connect's mongodb_cdc input. Covers Change Streams setup, snapshots, backfilling, document modes, and checkpointing with resume tokens.
Ships in redpanda. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
The mongodb_cdc input in Redpanda Connect streams change data capture (CDC) from a MongoDB database into Redpanda or any Kafka-compatible topic. It uses MongoDB Change Streams (requires MongoDB 4.0+ running as a replica set or sharded cluster), and optionally snapshots all existing documents before switching to live change streaming. This is an Enterprise feature — a Redpanda Enterprise license is required.
The connector tracks its position in the change stream using a resume token, which is stored in a configured cache resource. On restart, it resumes from the last stored token rather than replaying from the beginning.
Change Streams require a replica set or sharded cluster — they are not available on standalone mongod instances.
# Connect via mongosh and check replication status
mongosh "mongodb://localhost:27017"
rs.status() # must show a replica set configuration
# Create a user with read on the target DB
# (covers find + listCollections + changeStream action)
use admin
db.createUser({
user: "cdc_user",
pwd: "secret",
roles: [
{ role: "read", db: "mydb" }
]
})
# mongodb-cdc-pipeline.yaml
cache_resources:
- label: mongo_checkpoint
memory:
compaction_interval: "" # disable compaction/expiry (token persists for process lifetime)
input:
label: "mongo_cdc"
mongodb_cdc:
url: "mongodb://cdc_user:secret@localhost:27017/?replicaSet=rs0"
database: mydb
collections:
- orders
- customers
checkpoint_cache: mongo_checkpoint
checkpoint_key: mongodb_cdc_checkpoint # default
checkpoint_interval: 5s # default
checkpoint_limit: 1000 # default
stream_snapshot: true
snapshot_parallelism: 2
read_batch_size: 1000 # default
read_max_wait: 1s # default
document_mode: update_lookup # default
json_marshal_mode: canonical # default
pipeline:
processors:
- mapping: |
# Route each event to a per-collection topic
meta topic = "mongo.cdc." + meta("collection")
# Tag the key with the document _id.
# In canonical json_marshal_mode (the default) _id is an ExtJSON
# object like {"$oid":"..."}, so extract the inner string:
meta msg_key = this._id."$oid" | this._id.string() | ""
output:
redpanda:
seed_brokers: ["localhost:9092"]
topic: ${! meta("topic") }
key: ${! meta("msg_key") }
max_in_flight: 256
rpk connect run mongodb-cdc-pipeline.yaml
rpk topic consume mongo.cdc.orders --num 5 --brokers localhost:9092
read role on the target database — this covers find (snapshot), listCollections (schema discovery), and the changeStream action (Change Streams). For parallel snapshots via splitVector on self-managed clusters, also grant clusterManager on admin; alternatively set snapshot_auto_bucket_sharding: true to avoid that requirement. The hello/buildInfo startup commands require no special role.mongodb_cdc component is gated by license.CheckRunningEnterprise.mongodb_cdc opens a MongoDB Change Stream over the target database, filtered to the configured collections. MongoDB tracks position via an opaque resume token (not an integer offset). The connector stores the latest acknowledged token in the configured cache resource every checkpoint_interval (default 5s), writes one final token on clean shutdown, and — as of Connect 4.106.0 — writes a checkpoint as soon as the initial snapshot completes and is fully acknowledged, so a restart after the snapshot resumes the stream instead of re-snapshotting.
On startup, if no cached token is found, the connector:
stream_snapshot: true, reads all existing documents (operation = "read").If a token is found, the connector resumes directly from that position using ResumeAfter.
The document_mode field controls what body is emitted for update and delete events:
| Mode | Updates | Deletes |
|---|---|---|
update_lookup (default) | Full document after the update (via UpdateLookup). Falls back to documentKey if the document was deleted before lookup. | Only _id populated (documentKey). |
pre_and_post_images | Full document before and after (requires MongoDB 6.0+ and changeStreamPreAndPostImages enabled on each collection). | Full document before deletion. |
partial_update | A structured diff: {_id, operations: [{path, type, value}]} where type is set, unset, or truncatedArray. Enables showExpandedEvents on MongoDB 6.1+. | Only documentKey. |
Every message emitted by mongodb_cdc carries:
| Metadata key | Value |
|---|---|
operation | "read" (snapshot), "insert", "update", "replace", or "delete" |
collection | Collection name (e.g., "orders") |
operation_time | BSON timestamp in JSON form: {"$timestamp":{"t":<unix_sec>,"i":<ordinal>}} |
schema | Inferred or validator-derived schema in benthos common schema format (immutable; absent when no schema can be determined, e.g., deletes without pre-images) |
The connector uses a two-tier strategy to populate the schema metadata:
$jsonSchema validator. If found, this provides accurate types and required/optional field classification.The schema is re-inferred when the top-level field set of a document changes. Type changes within existing fields and nested subdocument structural changes are not auto-detected — restart to force a full schema refresh.
Recommendation: for schema-registry targets with compatibility modes, configure a $jsonSchema validator on each watched collection to stabilize the schema.
Since Connect 4.106.0, mongodb_cdc (and the mongodb input, output, processor and cache) can authenticate with the driver-native MONGODB-AWS mechanism instead of a static username and password, via an aws config block:
input:
mongodb_cdc:
url: "mongodb+srv://cluster0.abc123.mongodb.net/"
database: mydb
aws:
enabled: true # default false
collections: [orders]
checkpoint_cache: mongo_checkpoint
Rules that matter when choosing this path:
aws.enabled: true is mutually exclusive with username/password and with credentials embedded in url — either combination is a startup error.aws.role, aws.roles, or session tokens) is rejected for the mongodb processor and cache, which establish their client once at creation and cannot refresh expiring session credentials. Use the ambient chain or long-lived access keys there.mongodb_cdc, credentials are re-resolved after the initial snapshot completes, so streaming starts with a full session — but the snapshot itself must finish inside one session, because snapshot progress is not checkpointed. For very large snapshots, prefer the ambient chain.Per-field detail (region, session_duration, id/secret/token, role/role_external_id, roles[]) is in Config Reference and the generated connector reference.
Since Connect 4.116.0 there are three ways existing documents are read, and the first two are
mutually exclusive snapshot modes — setting both stream_snapshot: true and
incremental_snapshot.enabled: true is rejected at startup, because both read the same documents
and enabling both would deliver everything twice.
| Mode | How it reads | Pick it when |
|---|---|---|
stream_snapshot: true | An up-front snapshot of every collection, then streaming | You want the backfill complete before any change is delivered |
incremental_snapshot.enabled: true | Collections are read in _id-ordered chunks alongside streaming, from the start | Streaming must not wait for a large backfill |
A snapshot-execute signal | Reads the named collections in chunks alongside streaming, on demand | You are adding a collection, or re-reading one, on a running pipeline |
The third works in every snapshot mode: incremental_snapshot.enabled is not required for a
signal to queue a read. The rest of the incremental_snapshot block (chunk size, the progress
cache key, the retry cooldown) governs signal-requested reads too.
Incremental reads are chunked and each chunk is released once the change stream has caught up with
the moment it was read, so a chunk that a live write superseded is dropped rather than reverting
it. Progress is stored in checkpoint_cache under incremental_snapshot.checkpoint_cache_key,
separate from the stream position, so a restart continues from the last acknowledged chunk.
Two constraints the input enforces at startup: incremental_snapshot.checkpoint_cache_key must
differ from checkpoint_key (the two are stored separately), and
incremental_snapshot.chunk_size must not exceed checkpoint_limit — a chunk goes in flight as a
whole, so a larger one stalls streaming until everything before it is acknowledged.
Read the field types, defaults and the full block from the generated reference or
rpk connect create mongodb_cdc.
signal_collection_name names a collection in database that the input watches for control
documents while it runs. Each is {"type": ..., "data": ...}, where data may be a subdocument or
a JSON string: log logs data.message, and snapshot-execute queues a chunked read of the
collections it names. MongoDB has collections rather than tables, so the payload accepts
collections alongside the shared tables key, and the two are merged:
db.connect_signals.insertOne({
type: "snapshot-execute",
data: { collections: ["orders"] }
})
Four traps, each enforced or logged by the connector:
collections. The input rejects that
config at startup — its own inserts would be read back as signals.collection metadata set to the
signal collection. Filter them out downstream if you do not want them in the topic.collections is rejected, logged at error, and
nothing else reports it — the stream carries on. Nothing outside the watched set can be
deduplicated against the chunks, which is why it is refused. A collection already queued or
being read is skipped and logged at info, not an error.incremental_snapshot.enabled is true or a
signal_collection_name is set. With neither, the input discards what is stored under the
progress key, and enabling either later will not resume a read the stream has long since moved
past.Unlike postgres_cdc, pointing incremental_snapshot.checkpoint_cache_key at a fresh key does
not cause a new read: with a stream position stored, a restart treats every collection as
already read. Re-reading a collection takes a snapshot-execute signal.
When stream_snapshot: true and no resume token is cached, the connector snapshots all documents in each collection before streaming live changes.
snapshot_parallelism.snapshot_parallelism: 1, the default): each collection is read sequentially with a single cursor.snapshot_parallelism > 1): each collection is split into snapshot_parallelism _id-range buckets read concurrently, using splitVector (self-managed, requires clusterManager role) or $bucketAuto (when snapshot_auto_bucket_sharding: true, for Atlas where splitVector is disallowed).The read_batch_size field controls the MongoDB cursor batch size for both snapshot and streaming phases.
The checkpoint_cache field is required — you must provide a named cache resource. This cache stores the resume token as BSON Extended JSON.
For development (non-persistent, resets on restart):
cache_resources:
- label: mongo_checkpoint
memory:
compaction_interval: "" # empty string disables compaction and expiry
For production (persistent across restarts), use Redis:
cache_resources:
- label: mongo_checkpoint
redis:
url: redis://localhost:6379
To use document_mode: pre_and_post_images, you must enable this feature on each collection:
// Enable at collection level
db.runCommand({
collMod: "orders",
changeStreamPreAndPostImages: { enabled: true }
})
This requires MongoDB 6.0+ — changeStreamPreAndPostImages was introduced in 6.0. Use document_mode: update_lookup on MongoDB 4.x–5.x.
The resume token references a position in the oplog. If the pipeline falls behind or is stopped for longer than the oplog retention window (default 24 hours on Atlas; configurable with --oplogMinRetentionHours on self-managed clusters), MongoDB can no longer resume from the stored token. Size the oplog so the window comfortably exceeds the longest expected lag or downtime under peak write load.
When a stored position can no longer be resumed from (aged out of the oplog, or another non-resumable change-stream condition), the connector no longer just errors out — it recovers rather than retrying a dead position:
stream_snapshot: true — it clears the checkpoint and re-runs the snapshot, which loses nothing. A breaker bounds this: after 3 consecutive recoveries with no change-stream advance in between (usually a snapshot that takes longer than the oplog window), it keeps the checkpoint and fails on every reconnect with an actionable error instead of re-snapshotting forever. Fix the underlying cause — grow the oplog, speed the snapshot up — then restart the pipeline (or delete the checkpoint cache entry) to resume recovery.stream_snapshot: false — there is no snapshot to re-run, so recovery would mean skipping the changes between the lost position and now. The connector refuses to do that silently: on_unresumable_position (default fail) preserves the checkpoint and errors on every reconnect; skipping the gap must be opted into with on_unresumable_position: reset.checkpoint_write_timeout (default 10s, advanced) bounds the two checkpoint writes that run outside the read loop — storing the position a completed snapshot reached, and clearing an unresumable one — so a slow cache cannot extend shutdown indefinitely. Raise it for slow remote caches (redis, dynamodb), where losing the post-snapshot write costs a full re-snapshot on the next start.
On restart with a valid cached token, the connector immediately opens the change stream at the stored position — no up-front snapshot is performed regardless of the stream_snapshot setting. That snapshot only runs when no checkpoint exists; because the completed snapshot's position is now checkpointed once fully acknowledged, a restart after a finished snapshot resumes the stream rather than snapshotting again.
An incremental read is the exception: a restart resumes it from the last acknowledged chunk, since its progress is checkpointed separately under incremental_snapshot.checkpoint_cache_key. A snapshot-execute signal is checkpointed into the queue before the transaction carrying it is acknowledged, so a restart does not lose a read that was requested but not yet started.
All configured collections are consumed through a single database-level change stream — the collection list is a server-side filter on that one stream, not a set of independent streams. A change stream is one totally-ordered cursor over the replica set's oplog, so throughput does not grow with more collections, and the input does not use CPU beyond roughly two cores. This is a property of MongoDB change streams, not of the connector. To scale past that ceiling, shard the cluster: a change stream against a sharded cluster merges parallel per-shard cursors server-side.
On MongoDB Atlas, the splitVector command is not available. Set snapshot_auto_bucket_sharding: true to use $bucketAuto aggregation for parallel snapshots instead.
The mongodb_cdc input is itself an Enterprise connector, and the topics it
feeds pair with other Redpanda enterprise differentiators (all require a valid
Enterprise license — see Enterprise Integration
for nested keys and examples):
iceberg_enabled=true, then topic redpanda.iceberg.mode
(key_value for raw CDC JSON, or value_schema_id_prefix/value_schema_latest
for schema-serialized events), plus redpanda.iceberg.delete,
redpanda.iceberg.invalid.record.action (drop/dlq_table),
redpanda.iceberg.partition.spec, redpanda.iceberg.target.lag.ms.enable_schema_id_validation
(none/redpanda/compat); topic redpanda.value.schema.id.validation +
redpanda.value.subject.name.strategy (and key equivalents).redpanda.remote.write +
redpanda.remote.read, with retention.local.target.ms/.bytes bounding the
local footprint.tls.client_certs[], tls.root_cas_file) and SASL
(sasl[].mechanism: SCRAM-SHA-512/PLAIN/OAUTHBEARER); OAUTHBEARER/OIDC
and Kerberos broker auth are Enterprise.mongodb_cdc input field with type, default, and description grounded in source.redpanda.iceberg.*), Server-side Schema ID Validation (enable_schema_id_validation, redpanda.{key,value}.schema.id.validation), Tiered Storage (redpanda.remote.*, retention.local.target.*), sink TLS + SASL (SCRAM/OAUTHBEARER/Kerberos), RBAC, Connect secrets management, FIPS, and allow/deny lists. Notes which require an Enterprise license.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
cdc, change-data-capture, mongodb-cdc, redpanda-connect, kafka-streaming
36 skills in this plugin
/adpRedpanda's Agentic Data Plane: governance infrastructure for building, running, and governing AI agents and MCP servers behind a credential-injecting AI Gateway for LLM providers, operated through the `rpk ai` CLI and the ADP UI at ai.redpanda.com. Use when installing `rpk ai`, signing in to an environment, checking setup with `rpk ai doctor`, managing managed or self-managed AI agents and their triggers with `rpk ai agent` and `rpk ai trigger`, configuring remote or managed MCP servers with `rpk ai mcp-server` (including code mode and user-delegated OAuth), setting up LLM providers and models with `rpk ai llm-provider` and `rpk ai model`, applying GitOps manifests, or launching a coding tool with `rpk ai run`. For access policies, budgets and cost, guardrails and the kill switch, or secrets, API keys, data policies and OAuth, see `/redpanda:adp-governance`. For transcripts, the audit log, and traces, see `/redpanda:adp-observability`. For the `rpk cloud mcp` control-plane server, see `/redpanda:rpk-cloud`./adp-governanceGovern what Agentic Data Plane agents may do, spend, and expose, through the `rpk ai` CLI and the ADP UI at ai.redpanda.com, and look up governance features in the Redpanda docs. Use when writing or debugging a Cedar access policy with `rpk ai policy`, giving a new agent access, capping agent spend with `rpk ai budget`, analyzing cost, attaching a guardrail to a provider, containing or releasing an agent with the kill switch, storing or deleting a credential with `rpk ai secret`, minting an API key, masking MCP tool data with data policies, or setting up inbound or outbound OAuth. For signing in, agents, MCP servers, LLM providers, and the rest of the `rpk ai` CLI, see `/redpanda:adp`. For transcripts, the audit log, and traces, see `/redpanda:adp-observability`.Other plugins' skills for the same job
npx claudepluginhub redpanda-data/skills --plugin redpanda