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.

Nested UNWIND with MATCH cuts off part of result data

Hello,
I'm not very good at cypher but currently I'm trying to solve batch create task. I'm using Neo4j DB v 4.0

So please consider we have batch of input data:

:param batch=>[{uuid:"5b12a325-36cd-418c-8cd5-7911cdb0ee33",authors:[{name: "Author1",lives: "City1"},{name: "Author2",lives: "City2"}]},{uuid:"b4d5cdf8-61ba-416d-ab29-ad9bf42dcf78",authors:[{name: "Author3",lives: "City1"},{name: "Author4",lives: "City2"}]},{uuid:"5add7aff-b8cc-4382-bfa4-02947b93b245",authors:[]}]

And with the following script I'm creating batch of nodes with label Book and return uuid of created book node

UNWIND $batch as row
CREATE (b:Book {uuid: row.uuid})
WITH b, row.authors AS authors
UNWIND (CASE authors WHEN [] then [null] else authors end) AS author
MATCH (c:City {name: author.lives})
CREATE (a:Author {name: author.name})
CREATE (a)-[:livesIn]->(c)
CREATE (b)-[:writtenBy]->(a)
RETURN distinct(b.uuid)

As a result I receive 2 uuids but expecting 3, as in fact 3 books were created. Is there any way to return all 3 ids?

1 REPLY 1

Probably you don't find the city for one of the authors?

You could use an OPTIONAL MATCH or a MERGE there.