Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-14-2022 11:03 AM
When I run the following query, it extracts the path between nodes.
//ShortestPath planning
match (g:Id1 {start_marker:1}),
(c:Id2 {break_point:1}),
p = shortestPath((g)-[*]->(c))
return p
Then I extracted that result using a procedure apoc.export.cypher.query
, and when I uploaded the data back into the database, the result was following:
And that is exactly what I wanted.
How can I write that result straight into the database within my original query?
03-16-2022 04:59 AM
A shortest path from any element A to any other node B in the database is already written in the database; the path is already there.
Now, given your path, what you could do is iterate through the relationships and set some property on them indicating "follow this relationship for shortest path from A to B" if you wanted to. For that, I'd use the rels() function on the path p
object that you have.
For example, something like this:
match (g:Id1 {start_marker:1}),
(c:Id2 {break_point:1}),
p = shortestPath((g)-[*]->(c))
WITH relationships(p) as relsInShortestPath, g, c
UNWIND relsInShortestPath as singleRel
SET singleRel.shortestPathFrom=id(g), singleRel.shortestPathTo=id(c)
RETURN count(singleRel)
All the sessions of the conference are now available online