cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Create New Nodes from Array

RedInk
Node Link

Greetings,

Using node.js and Express

I have an input field name="tablenames" and I can pass this to my server using const {tablenames} = req.body and I can console.log and see an array of the expected table names...

console.log(tablenames);

[table1, table2, table3, table4, table5]

I am trying to take the tablenames array and build 5 new nodes each with the .Title of a given table seen in the array.

I've tried the following queries, but am at a loss as to how to do what I thought would be a fairly simple task.

Try 1

 

Merge (t:Table {Title: $tablenames})

 

The result of this is 1 new node created with all 5 of the table1~5 as the .Title

Try 2

 

UNWIND $tablenames AS map
CREATE (n:Table)
SET n = map.Title

 

I realize I'm not using map correctly as it return an error, but I'm trying to follow the Create documentation for creating multiple nodes.

How do I create these 5 separate nodes from the array and give them the titles listed in the array?

Many Thanks!

1 ACCEPTED SOLUTION

glilienfield
Ninja
Ninja

Try this:

 

UNWIND $tablenames AS table
CREATE (n:Table)
SET n.Title = table

Or this:

forEach(i in $tablenames |
CREATE (n:Table)
SET n.Title = i)

 

View solution in original post

2 REPLIES 2

glilienfield
Ninja
Ninja

Try this:

 

UNWIND $tablenames AS table
CREATE (n:Table)
SET n.Title = table

Or this:

forEach(i in $tablenames |
CREATE (n:Table)
SET n.Title = i)

 

RedInk
Node Link

Perfect, thank you!