Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-23-2020 04:00 AM
I have a use case where
Create new node if there is no node with given id
Return existing node if node exists with given id
return null if given id is null
Ex: User({emailId: 'x.com'})
If email id is null, then it should return null
Solved! Go to Solution.
11-24-2020 02:14 AM
solved this way
foreach(
managerEmailId in CASE when ${'$'}managerEmailId IS NOT NULL THEN[${'$'}managerEmailId] ELSE [] END |
merge (u)<-[:IS_MANAGER_OF]-(:User {email_id : managerEmailId, tenant_id: ${'$'}tenantId})
)
with u
11-23-2020 08:28 AM
merge
https://neo4j.com/docs/cypher-manual/4.2/clauses/merge/ will do create if not exists otherwise return but does not account for if null.
For example
merge (n: User({emailId: 'x.com'}) return n;
will create the node and then return the node if it the node does not already exist and if the node already exists it will simply return the node and not create a new node.
Note the documentation link above refers to Neo4j 4.2 documentation. It should be the same for all versions of Neo4j but as the initial problem description provided no version details
11-23-2020 08:40 PM
There is a problem with syntax of your merge statement.
11-24-2020 02:14 AM
solved this way
foreach(
managerEmailId in CASE when ${'$'}managerEmailId IS NOT NULL THEN[${'$'}managerEmailId] ELSE [] END |
merge (u)<-[:IS_MANAGER_OF]-(:User {email_id : managerEmailId, tenant_id: ${'$'}tenantId})
)
with u
All the sessions of the conference are now available online