Use Change Data Capture

Change Data Capture (CDC) queries can be created with the Cypher® Builder by using the Procedures in the cdc namespace:

  • Cypher.db.cdc.current()

  • Cypher.db.cdc.earliest()

  • Cypher.db.cdc.query(from, selectors)

Previous to Neo4j version 5.17, the namespace for cdc procedures is cdc.x instead of db.cdc.x, this namespace is available in Cypher Builder through the deprecated functions Cypher.cdc.x

Examples

Acquiring the current change identifier

In order to query changes, you need to acquire a change identifier. This can be done with cdc.current() or cdc.earliest(). To acquire the latest change identifier, follow these instructions:

const query = Cypher.db.cdc.current().yield("id");
const { cypher } = query.build();
CALL db.cdc.current() YIELD id

Querying changes

To query changes in the graph, follow these instructions:

const query = Cypher.db.cdc.query(fromId);
const { cypher } = query.build();
CALL db.cdc.query("cdc-id", [])

Using query selectors

To use CDC selectors you’ll need to define a Map with the properties of the selector schema for each selector:

const fromId="cdc-id";
const selector = new Cypher.Map({
    select: new Cypher.Literal("e"),
    operation: new Cypher.Literal("c"),
    changesTo: new Cypher.List([new Cypher.Literal("name"), new Cypher.Literal("title")]),
});


const query = Cypher.db.cdc.query(fromId, [selector]);
const { cypher } = query.build();
CALL db.cdc.query("cdc-id", [{
    select: "e",
    operation: "c",
    changesTo: ["name", "title"]
}])