Create Relationship if the Relationship Type is not existing

HI
I want to create a relationship if the node does not have this Relationship TYPE already: I tried

MATCH (node), (ac:account {name:'_ADMIN'}) 
WITH node,ac
WHERE NOT ((node)-[:owner_of]->(),
CREATE ((ac)-[:owner_of]->(node));

This gives me

Invalid input ';': expected whitespace, '.', node labels, '[', '^', '*', '/', '%', '+', '-', "=~", IN, STARTS, ENDS, CONTAINS, IS, '=', '~', "<>", "!=", '<', '>', "<=", ">=", AND, XOR, OR, ',' or ')' (line 5, column 34 (offset: 126))
"CREATE ((ac)-[:owner_of]->(node));"

I don't want this

MATCH (node), (ac:account {name:'_ADMIN'}) MERGE(ac)-[:owner_of]->(node);

this creates a relationship if the relationship between the 2 Nods is not exsiting- I need a check for the Relationship to any other node ...

THANKS rob

  • looks like another simple mistake by me

MATCH (node), (ac:account {name:'_ADMIN'})
WITH node,ac
WHERE NOT (node)-[:owner_of]->()
CREATE ((ac)-[:owner_of]->(node));

BUT the command seems not cerateing every Relathionship
after i run the command it telss me that 9 Relationships are created --- But ther are still some left with NO Relationship of type owner_of

MATCH (node) WHERE NOT (node)-[:owner_of]->() AND NOT node:status return node.name;
+----------------------+
| node.name |
+----------------------+
| "Procces Process" |
| "Org Process" |
| "Account Process" |
| "_AdminOrg" |
| "admin@local" |
| "admingroup@local" |
| "rootmessages@local" |
| "Person Process" |
| "Mail Process" |
+----------------------+

wrong direction

MATCH (node), (ac:account {name:'_ADMIN'}) WITH node AS ND,ac WHERE NOT (node)<-[:owner_of]-() AND NOT node:status CREATE ((ac)-[:owner_of]->(ND));

Hi @rob2

First of all, remove the round brackets at the beginning and end of the CREATE statement.
And remove '_ADMIN' from (node).

MATCH (node), (ac:account {name: '_ADMIN'})
  WHERE node <> ac
WITH node, ac
  WHERE NOT (node)-[:owner_of]->()
CREATE (ac)-[:owner_of]->(node);