cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Multiple CALL statements in single query returns no records

Hello,

I have the following query, where I aim to MERGE a list of $nodes:

tx.run(
     `MATCH (u:User { id: $userId })
       UNWIND $nodes AS map
       MERGE (n:ProjectNode { id: map.id })
       ON CREATE SET
         n.createdAt = timestamp(),
         n.isCreated = true
       ON MATCH SET
         n.updatedAt = timestamp(),
         n.isCreated = false
       SET n += map
       WITH n, u, p
       CALL apoc.do.when(n.isCreated,
                         "MERGE (u)-[:AUTHORED]->(n) REMOVE n.isCreated RETURN u as author",
                         "MATCH (a:User)-[:AUTHORED]->(n) REMOVE n.isCreated RETURN a as author",
                         { n: n, u: u })
       YIELD value
       WITH n, p, value.author as author
       CALL apoc.do.when(EXISTS(n.assignee),
                          "MATCH (a:User { id: n.assignee }) CREATE (a)-[:ASSIGNEE]->(n) REMOVE n.assignee RETURN a as assignee",
                          "MATCH (a:User)-[:ASSIGNEE]->(n) RETURN a as assignee",
                          { n: n })
       YIELD value
       RETURN n, p, author as author, value.assignee as assignee`,
      { nodes, userId })

In this query, I am iterating through $nodes by using unwind, and for each node I wish to a) set any of the supplied properties, b) create a relationship to an author if the node is being created on merge, else return the existing author, and c) create a relationship to an assignee if the "assignee" key is specified in the node, else return the existing assignee. For some reason, adding the second CALL statement to conditionally create the assignee causes the entire query to return zero records. If I remove the second CALL statement (along with the subsequent YIELD), the query seems to work fine. Anyone know why this might be the case?

1 REPLY 1

@mng12689
There is a variable p not defined in your query, maybe a copy-paste error?
However, apart for the p,
I doesn't see anything wrong with this query.
I tested it with some fake data and it works.

Maybe the MATCH clauses in 2nd when don't work properly..
Can you provide a sample dataset to reproduce your issue?