Skip to content

MongoDB target

TwinCommit applies changes to MongoDB with bulkWrite upserts. The document _id comes from the source primary key. Each batch and its checkpoint document are written in one multi-document transaction, so delivery is exactly-once.

Supported: MongoDB 6.0, 7.0 and 8.x replica sets and sharded clusters · MongoDB Atlas.

target:
type: mongodb
uri: mongodb+srv://twincommit:${MONGO_TARGET_PASSWORD}@cluster1.example.mongodb.net/
database: replica
id_field: _id # single-column PKs map to _id; composite PKs become an embedded document
nest: [] # optional: embed child tables, see below
  • Inserts and updates become replaceOne with upsert: true, filtered on _id.
  • Deletes become deleteOne.
  • The batch and the checkpoint document in state_schema are committed in one transaction.

Use nest to embed rows from a child table as an array in the parent document:

nest:
- parent: SALES.ORDERS
child: SALES.ORDER_LINES
field: lines
join: [ORDER_ID]
db.getSiblingDB("admin").createUser({
user: "twincommit", pwd: "********",
roles: [{ role: "readWrite", db: "replica" }]
})