Support a shared `mongodb-cdc` source: one source, multiple CDC tables (as MySQL/PostgreSQL CDC already do)
Is your feature request related to a problem? Please describe.
We ingest a MongoDB database with ~50 collections into RisingWave (v3.0.1, standalone). Each
collection currently needs its own CREATE TABLE ... WITH (connector = 'mongodb-cdc'), and each of
those is a separate Debezium engine with its own change stream. That does not scale on either side:
- RisingWave side — every engine lives in the same embedded connector JVM, whose heap defaults to
DEFAULT_MEMORY_PROPORTION = 0.07of container memory (jni_core/src/jvm_runtime.rs), i.e. ~1.15 GiB at a 16 GiB limit. Creating 15 pipelines in one deployment reliably ends inTerminating due to java.lang.OutOfMemoryError: Java heap space, which takes the whole standalone process down. (SettingJVM_HEAP_SIZEexplicitly raises the ceiling, but the per-engine cost stays linear in the number of collections.) - MongoDB side — N tables mean N independent server-side change streams, so the same oplog is scanned N times, even though MongoDB can serve a whole database from a single change stream.
MySQL and PostgreSQL CDC already solve exactly this with a shared source: one CREATE SOURCE,
then one CREATE TABLE ... FROM <source> TABLE '<schema>.<table>' per table. MongoDB has no equivalent.
Describe the solution you'd like
A shared mongodb-cdc source with the same shape as the MySQL/PostgreSQL one — one connector, one
change stream, and one independent table per collection:
CREATE SOURCE mongo_mydb WITH (
connector = 'mongodb-cdc',
mongodb.url = 'mongodb://...'
);
CREATE TABLE src_orders (_id JSONB PRIMARY KEY, payload JSONB) FROM mongo_mydb TABLE 'mydb.orders';
CREATE TABLE src_invoices (_id JSONB PRIMARY KEY, payload JSONB) FROM mongo_mydb TABLE 'mydb.invoices';Separate tables are the point, not just a convenience — they preserve everything we depend on today:
- independent initial snapshots, so onboarding can be paced collection by collection instead of igniting every snapshot at once;
- independent recovery — a single wedged/corrupted collection can be dropped and re-snapshotted without touching the other 49;
- independent primary keys, so
_iduniqueness stays per collection where MongoDB defines it; - per-collection materialized views, sinks, and rate limits.
The internal machinery for the "one stream, many collections" half already exists: when
collection.name is given a regex, RisingWave opens a single deployment-level change stream
(verified via $currentOp: one tailable cursor at admin.$cmd.aggregate). What is missing is fanning
that one stream out to multiple tables, which is what the MySQL/PostgreSQL shared source already does.
Describe alternatives you've considered
1. A shared CREATE SOURCE — currently unreachable. The parser requires
FORMAT PLAIN ENCODE JSON for CDC sources, and the MongoDB connector rejects that format:
CREATE SOURCE mongo_shared WITH (connector = 'mongodb-cdc', mongodb.url = '...');
-- Protocol error: connector mongodb-cdc does not support format Plain
CREATE SOURCE mongo_shared WITH (connector = 'mongodb-cdc', mongodb.url = '...')
FORMAT DEBEZIUM_MONGO ENCODE JSON;
-- sql parser error: Row format for CDC connectors should be either omitted
-- or set to `FORMAT PLAIN ENCODE JSON`2. The existing multi-collection table — works, but silently loses rows. One engine for many
collections is possible today by pointing collection.name at a regex, and
INCLUDE COLLECTION_NAME identifies the origin. The problem is that the resulting table is keyed on
_id alone, while MongoDB only guarantees _id uniqueness within a collection. Documents from
different collections that share an _id overwrite each other with no error:
// mongosh — two collections, one deliberately shared _id
db.collA.insertMany([{_id: "1", v: "A1"}, {_id: "2", v: "A2"}])
db.collB.insertMany([{_id: "1", v: "B1"}, {_id: "3", v: "B3"}])CREATE TABLE shared (_id JSONB, payload JSONB) -- no PRIMARY KEY declared
INCLUDE COLLECTION_NAME AS coll
WITH (connector = 'mongodb-cdc', mongodb.url = '...', collection.name = 'mydb.coll.*')
FORMAT DEBEZIUM_MONGO ENCODE JSON;
SELECT coll, _id, payload ->> 'v' AS v FROM shared ORDER BY 1, 2; coll | _id | v -- 3 rows instead of 4:
-------+-----+----- -- collA's _id = "1" is gone, no error, no warning
collA | "2" | A2
collB | "1" | B1
collB | "3" | B3Every attempt to key that table safely was rejected on v3.0.1:
| Attempt | Result |
|---|---|
PRIMARY KEY (coll, _id) with INCLUDE COLLECTION_NAME AS coll |
Internal error: Index 2 out of bounds for length 2 |
| Adding a third declared column to key on | must be (_id [Jsonb | Varchar | Int32 | Int64], payload jsonb) |
PARTITION BY LIST (coll) |
parser error (no declarative partitioning) |
Omitting PRIMARY KEY (as above) |
accepted, but rows are still deduplicated by _id |
| Re-keying downstream in a materialized view | too late — the row is already gone in the source table |
So grouping is only safe when every _id in the group is globally unique (e.g. all ObjectId). Ours
are per-collection numeric sequences, which makes this workaround unusable for us — and, we suspect,
for anyone whose ids are collection-scoped.
3. One table per collection (what we do today). Correct, but it is exactly the N-engines / N-change-streams situation described above.
Additional context
- Version: RisingWave v3.0.1, standalone, Helm chart
risingwave-0.2.55; MongoDB replica set; 15 pipelines / ~14.5 M documents in the test environment, ~50 collections planned. - Questions:
- Is a shared
mongodb-cdcsource supported in a newer version, or on the roadmap? If there is a design constraint that makes it harder than for MySQL/PostgreSQL, we would like to understand it. - Independently: should the multi-collection
collection.nameform document (or reject) the case where_idis not unique across the group? Silent row loss is a surprising default — an error at DDL time, or a required key declaration, would be much safer.
- Is a shared
- We are happy to test a patch or nightly build against our setup and report back.
Source: risingwavelabs/risingwave