Cypher dynamic node based on unwind list value

Hi all,

I am writing cypher query that inserts values based on JSON values passed with UNWIND. Values are working as expected, but I want to make node name dynamic, based on "class" value on JSON.

Here's working example

UNWIND [{id: "199" , container_id: "203", acl_id: "1047", class: "Usergroup" }] as event 
MATCH (u:User {id:})  // I am trying to make User node dynamic in this line
MATCH (ug:Usergroup {id: event.container_id}) 
OPTIONAL MATCH (u)-[r:CHILD_OF]->(:Usergroup) 
SET u.acl_id = event.acl_id ;
CREATE (u)-[rel:CHILD_OF]->(ug);

When I try to change this row

MATCH (u:User {id:}) 


MATCH (u:event.class {id:}) 

I see this error "Neo.ClientError.Statement.SyntaxError: Invalid input '.': expected ")", "{" or "$" "

What am I doing wrong here?

not so much that you are doing anything wrong other than labels can not be dynamically set, primarily because the query planner might not know what value event.class represents. In your case its clear event.class only has 1 value but thats specific to your case. If the UNWIND as a list of 10 items and each item had a different class value, i.e. UserGroup, Group, User, etc.. then the planner is simply not able to determine how it should run said match when it is for a variety of different labels

This would be no different than in a RDBMS world if one ran

select * from $Table ;

and where $Table could for example be one of 10 different values

Now as to how to overcome this you might want to consider using See - APOC Extended Documentation