Decard Cain
Decard Cain

Reputation: 27

Using UNWIND and CREATE to create multiple relationships

I have the following query:

UNWIND [100, 200, 300] AS CODENUM
MATCH (system1:System), (group1:SystemGroup)
WHERE system1.Name = 'Main' AND group1.Name = 'MainGroup'
CREATE (system1)-[:CODE_CODENUM]->(group1)

it creates 3 relationships, but the name remains the same for all - CODE_CODENUM

I want CODE_100, CODE_200, CODE_300 How to achieve this?

I tried wrapping CODENUM in curely brackets but I get error:

Neo.ClientError.Statement.ParameterMissing: Expected Parameter(s): CODENUM

Upvotes: 0

Views: 265

Answers (1)

Tomaž Bratanič
Tomaž Bratanič

Reputation: 6524

To be able to create relationships with dynamic type you will need to use APOC library.

Here is an example:

 UNWIND [100, 200, 300] AS CODENUM
 MATCH (system1:System), (group1:SystemGroup)
 WHERE system1.Name = 'Main' AND group1.Name = 
  'MainGroup'
  CALL apoc.create.relationship(system1, 'CODE_' 
          +CODENUM,{}, group1) YIELD rel
   RETURN distinct true

Upvotes: 1

Related Questions