Examples
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.
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.
CALL db.cdc.query($previousChangeId, [{
select: "e",
changesTo: ["name"]
}])
CALL db.cdc.query($previousChangeId, [{
select: "n",
changesTo: ["name"]
}])
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.
CALL db.cdc.query($previousChangeId, [{
select: "e",
executingUser: "alice"
}])
CALL db.cdc.query($previousChangeId, [{
select: "n",
authenticatedUser: "alice",
executingUser: "bob"
}])
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.
CALL db.cdc.query($previousChangeId, [{
select: "n",
elementId: "4:e239be76-c7e8-43d8-aa03-567de592f426:0"
}])
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.
CALL db.cdc.query($previousChangeId, [{
select: "n",
key: {
name: "Kevin",
surname: "Bacon"
}
}])
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.
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.
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.
CALL db.cdc.query($previousChangeId, [{
select: "r",
start: {
labels: ["Person"]
}
}])
CALL db.cdc.query($previousChangeId, [{
select: "r",
start: {
labels: ["Person"]
},
end: {
labels: ["Movie"]
}
}])
CALL db.cdc.query($previousChangeId, [{
select: "r",
type: "ACTED_IN",
start: {
labels: ["Person"]
},
end: {
labels: ["Movie"]
}
}])
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"
}
}
}])
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"]
}
}])