Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-13-2023 01:10 PM
Not sure if this is the correct location for this question, but I am trying to use apoc.do.when with my neo4j version 5 instance. I have been trying to use the docs to create my query but for some reason one of my parameters is not being changed correctly in my query string and I am not sure why.
LOAD CSV WITH HEADERS FROM 'file:///pcs.csv' AS row
with row, row.left as left, row.left_type as left_type
CALL apoc.do.when(
row.concept IS NOT NULL,
'CREATE (n:left_type {id: left }) RETURN n AS node',
'CREATE (c:Node{name:"C"}) RETURN c AS node',
{left_type:left_type,left:left})
YIELD value
RETURN value.node AS node;
When I read in the rows of the csv some rows have a concept value and some don't. Based on this I want to create different nodes in the database. The condition is working and the "left" parameter is being correctly changed but left_type is still called left_type not the actual label it should be.
{
"identity": 507,
"labels": [
"left_type"
],
"properties": {
"id": "1"
},
"elementId": "507"
}
Looks like this^
Any help would be useful
01-13-2023 02:12 PM - edited 01-13-2023 03:52 PM
You can not set a label with a variable. The 'left_type' in your 'create ' statement is setting the label to 'left_type'. If you want to set the label dynamically, you can use an apoc method to create the node and specify the label in the same procedure.
https://neo4j.com/labs/apoc/4.1/overview/apoc.create/apoc.create.node/
01-16-2023 04:32 AM
Thanks so much for the response. I was misunderstanding how to use parameters. Figured it out with your suggestion.
All the sessions of the conference are now available online