Examples

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 in which certain properties are changed. If a list of properties is provided, all of the provided properties must have been 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 in which the transaction matches specific metadata attributes.

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 elementId

Changes can be filtered to a specific elementId. This might be useful when you are interested in changes made to a specific node or relationship. See Cypher Manual → elementId for more information on getting elementIds of existing entities. Avoid using elementId in favor of business keys — see The role of elementIds and key properties for details.

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 having start node with a specific label
CALL db.cdc.query($previousChangeId, [{
    select: "r",
    start: {
        labels: ["Person"]
    }
}])
Query relationships between specific labels
CALL db.cdc.query($previousChangeId, [{
    select: "r",
    start: {
        labels: ["Person"]
    },
    end: {
        labels: ["Movie"]
    }
}])
Query relationships 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 involving 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"]
    }
}])