Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-15-2021 11:03 AM
After I run my code here:
MATCH (a:CALL)-[:RECEIVED_CALL]->(b:PERSON),(c:CALL) <-[:MADE_CALL]-(d:PERSON)
WHERE id(a) < 80 and id(c) < 80
WITH COLLECT([b,d]) as calls
UNWIND calls as callss
FOREACH (i IN callss | CREATE (d)-[r:KNOWS]->(b))
RETURN callss
I have this list:
Thank you very much for your time.
Solved! Go to Solution.
03-17-2021 09:46 PM
Usage of graph ids like this isn't recommended. If a node is deleted, its id becomes eligible for reuse in the future, so an approach like this doesn't have many guarantees about the nodes it will operate over.
What is weird here is that your query seems more complex than it needs to be, and it obscures what you're trying to do.
Your latest query shows that the calls a
and c
are actually the same node, since your restriction is that they have the same graph id. This is the same call! If all you're trying to do is MATCH to the caller and receiver of the same call and create a :KNOWS relationship between them, then we can do this far more clearly we just use a single CALL node:
MATCH (d:PERSON)-[:MADE_CALL]->(c:CALL)-[:RECEIVED_CALL]->(b:PERSON)
MERGE (d)-[:KNOWS]->(b)
RETURN d, c, b
03-16-2021 12:53 AM
Hello @iamtienng and welcome to the Neo4j community
MATCH (a:CALL)-[:RECEIVED_CALL]->(b:PERSON)
MATCH (c:CALL)<-[:MADE_CALL]-(d:PERSON)
WHERE id(a) < 80 AND id(c) < 80
WITH DISTINCT b, d
CREATE (d)-[r:KNOWS]->(b)
Why are you doing id(a) < 80
and not id(a) = 80
?
Regards,
Cobra
03-16-2021 02:04 AM
Thank you very much for your reply.
I did write id(a) < 80
instead of id(a) = 80
because I have around 1000 cases to do.
I used your solution and it still causes the error:
Best regards,
Tien Nguyen.
03-16-2021 02:10 AM
I found the solution:
UNWIND range(0, 100) as idf
MATCH (a:CALL)-[:RECEIVED_CALL]->(b:PERSON),(c:CALL) <-[:MADE_CALL]-(d:PERSON)
WHERE id(a)=idf and id(c)=idf
CREATE (d)-[r:KNOWS]->(b)
RETURN a,b,c,d
Thank you very much.
Best regards,
Tien Nguyen.
03-17-2021 09:46 PM
Usage of graph ids like this isn't recommended. If a node is deleted, its id becomes eligible for reuse in the future, so an approach like this doesn't have many guarantees about the nodes it will operate over.
What is weird here is that your query seems more complex than it needs to be, and it obscures what you're trying to do.
Your latest query shows that the calls a
and c
are actually the same node, since your restriction is that they have the same graph id. This is the same call! If all you're trying to do is MATCH to the caller and receiver of the same call and create a :KNOWS relationship between them, then we can do this far more clearly we just use a single CALL node:
MATCH (d:PERSON)-[:MADE_CALL]->(c:CALL)-[:RECEIVED_CALL]->(b:PERSON)
MERGE (d)-[:KNOWS]->(b)
RETURN d, c, b
04-19-2021 01:47 PM
Dear Andrew,
Your solution is so simple but yet extremely effective. Maybe I have not fully understood how Neo4j works.
Thank you so much for the replies even though I haven't logged in in a long time.
Best regards,
Tien Nguyen.
All the sessions of the conference are now available online