Examples

This feature has been released as a public beta in AuraDB Enterprise October Release and Neo4j Enterprise Edition 5.13 and breaking changes are likely to be introduced before it is made generally available (GA).

The examples in this section assume that the parameter $previousChangeId is populated with a change identifier, either from the result of a previous query or from using the current or earliest procedures.

Selecting entities based on operation type

Changes can be filtered to only return creates, updates or deletes, regardless of whether the effected entity is a node or a relationship.

Query
CALL db.cdc.query($previousChangeId, [{
    select: "e",
    operation: "c"
}])

Selecting entities based on changed properties

Changes can be filtered to only include those where a certain property or properties are changed. Note that if a list of properties is provided, for the change to be selected, all of the provided properties need to be changed in the same change event.

Query entities where a specific property is changed
CALL db.cdc.query($previousChangeId, [{
    select: "e",
    changesTo: ["name"]
}])
Query nodes where a specific property is changed
CALL db.cdc.query($previousChangeId, [{
    select: "n",
    changesTo: ["name"]
}])
Query relationships where a specific property is changed
CALL db.cdc.query($previousChangeId, [{
    select: "r",
    changesTo: ["registerId"]
}])

Selecting entities based on change metadata

Changes can be filtered to only include those where the transaction was carried out by a particular user or certain metadata property or properties have been associated with that transaction.

Query entities changed by a particular user
CALL db.cdc.query($previousChangeId, [{
    select: "e",
    executingUser: "alice"
}])
Query nodes changed by a user impersonating another
CALL db.cdc.query($previousChangeId, [{
    select: "n",
    authenticatedUser: "alice",
    executingUser: "bob"
}])
Query relationships changed when a specific metadata property was set on the transaction
CALL db.cdc.query($previousChangeId, [{
    select: "r",
    txMetadata: {
        correlationId: 123456789
    }
}])

Selecting nodes/relationships by element id

Changes can be filtered to a specific element id. This might be useful when you are interested in changes made to a specific node or relationship. See Cypher Manual → Functions → Scalar functions for more information on getting element ids of existing entities.

Query node changes
CALL db.cdc.query($previousChangeId, [{
    select: "n",
    elementId: "4:e239be76-c7e8-43d8-aa03-567de592f426:0"
}])
Query relationship changes
CALL db.cdc.query($previousChangeId, [{
    select: "r",
    elementId: "5:a439fca3-d8b3-35f0-aa49-987fa112f993:0"
}])

Selecting entities by key

Node changes can be filtered to match specified key properties. The provided key properties need to fully match to a corresponding node key or relationship key on the entity. See The role of elementIds and key properties for details.

Query node changes by key
CALL db.cdc.query($previousChangeId, [{
    select: "n",
    key: {
        name: "Kevin",
        surname: "Bacon"
    }
}])
Query relationship changes by key
CALL db.cdc.query($previousChangeId, [{
    select: "r",
    key: {
        registerId: 1001
    }
}])

If the related constraints are added after a change on an entity is captured, the previous change events are not updated retroactively and do not match key selectors.

Selecting nodes by label

Node changes can be filtered to specific labels.

Query
CALL db.cdc.query($previousChangeId, [{
    select: "n",
    labels: ["Person", "Actor"]
}])

The query above only returns changes on nodes that have both labels either before or after the change. In order to get changes on nodes with either label, two separate selectors have to be specified. See combining selectors for details.

Selecting relationships by type

Relationship changes can be filtered to a specific type.

Query
CALL db.cdc.query($previousChangeId, [{
    select: "r",
    type: "ACTED_IN"
}])

Selecting relationships by start/end nodes

Relationship changes can be selected based on their start and end nodes.

Query relationships that has a start node with a specific label
CALL db.cdc.query($previousChangeId, [{
    select: "r",
    start: {
        labels: ["Person"]
    }
}])
Query relationships that is between specific labels
CALL db.cdc.query($previousChangeId, [{
    select: "r",
    start: {
        labels: ["Person"]
    },
    end: {
        labels: ["Movie"]
    }
}])
Query relationships that is between specific labels and with a specific type
CALL db.cdc.query($previousChangeId, [{
    select: "r",
    type: "ACTED_IN",
    start: {
        labels: ["Person"]
    },
    end: {
        labels: ["Movie"]
    }
}])
Query relationships that involves a specific node
CALL db.cdc.query($previousChangeId, [{
    select: "r",
    start: {
        labels: ["Person"],
        key: {
            name: "john",
            surname: "doe"
        }
    }
}, {
    select: "r",
    end: {
        labels: ["Person"],
        key: {
            name: "john",
            surname: "doe"
        }
    }
}])
Query nodes and relationships of specific labels and types
CALL db.cdc.query($previousChangeId, [{
    select: "n",
    labels: ["Person"]
}, {
    select: "n",
    labels: ["Movie"]
}, {
    select: "r",
    type: "ACTED_IN",
    start: {
        labels: ["Person"]
    },
    end: {
        labels: ["Movie"]
    }
}, {
    select: "r",
    type: "DIRECTED",
    start: {
        labels: ["Person"]
    },
    end: {
        labels: ["Movie"]
    }
}])