RETURN apoc.any.rebind([p1, p2]) as rebind CREATE p1=(a:Foo)-[r1:MY_REL]->(b:Bar), p2=(:Bar)-[r2:ANOTHER_REL]->(c:Baz)
RETURN apoc.any.rebind({first: a, second: b, third: c, rels: [r1, r2]}) as rebind
CREATE (a:Foo)-[r1:MY_REL]->(b:Bar)-[r2:ANOTHER_REL]->(c:Baz) WITH a,b,c,r1,r2
For example:
This will return the same structure passed in the argument, but with rebound entities.
We can also use the `apoc.any.rebind(ANY)` to rebind multiple entities placed in maps, lists, paths, or a combination of these three.
MATCH (:Start)-[rel:REL]->(:End) /*...*/ RETURN apoc.rel.rebind(rel) // other operations...
Regarding relationships, we can use `apoc.rel.rebind`:
'CREATE (node:Category) with art, node call apoc.create.relationship(art, "CATEGORY", {b: 1}, node) yield rel return rel', {}); CALL apoc.periodic.iterate('MATCH (art:Article) RETURN art',
Alternatively, we can wrap with the `apoc.node.rebind` function the node that have to be rebound, like this:
WITH art, node call apoc.create.relationship(art, "CATEGORY", {b: 1}, node) yield rel return rel', {}); 'CREATE (node:Category) WITH id, node MATCH (art) where id(art) = id CALL apoc.periodic.iterate('MATCH (art:Article) RETURN id(art) as id',
That is:
(this operation is called rebinding).
that means doing a MATCH (n) WHERE id(n) = id(nodeId)
we can leverage return the internal id from the first statement and then match the node via id,
To solve the previous apoc.periodic,iterate
,
How to solve
Failed to invoke procedure `apoc.create.relationship`: Caused by: org.neo4j.graphdb.NotFoundException: Node[10] is deleted and cannot be used to create a relationship": 1
If we try to execute the second query the apoc.periodic.iterate will return an errorMessage
similar to this:
and finally we try to create a relationship between (:Article)
and (:Category)
via apoc.create.relationship (which uses under the hood the org.neo4j.graphdb.Node.createRelationshipTo()
).
then the second parameter of the apoc.periodic.iterate open a new transaction and create a node (:Category)
,
Basically, we create a node (:Article)
,
'CREATE (node:Category) with art, node call apoc.create.relationship(art, "CATEGORY", {b: 1}, node) yield rel return rel', {}); CALL apoc.periodic.iterate('MATCH (art:Article) RETURN art', // iterate all (:Article) nodes and new transaction and rel creation CREATE (:Article {content: 'contentBody'}); // node creation
Is what happens when we perform the following operation:
that is n1.createRelationshipTo(n2)
.
via org.neo4j.graphdb.Node.createRelationshipTo()
,
This can cause problems when for example, we create a node (called n1) in a transaction, open a new transaction in which we create another node (called n2) and execute
in Neo4j 4+ the entities hold a reference to their originating transaction. Unlike versions up to 3.5,