Greetings,
I'm using Node.js, Express, & Neo4j.
I have a form that passes parameters to the server and they are being passed, but 1 parameter is a single item and the other parameter contains multiple objects in an array. I'm trying to create all of these from scratch and then relate one to the many. At this point what I have works, but instead of one to many I can only create 1 node from each different parameter and relate them.
Here's my form code on the ejs page...
<% pubDataSource.forEach(function(pds){ %><input type\="text" name\="datasourcename" id\="title" value\="<%= pds.name %>"\>
<% pds.fields.forEach(function(fieldName) { %>
<input type\="text" name\="datasourcefieldname" id\="title" value\="<%= fieldName.name %>"\>
<% }) %><% }) %>
<input class\="button" type\="submit" value\="Submit"\>
</form>
The items being passed are this...
datasourcename = Datasource_Model
datasourcefieldname = ['fieldnameOne', 'fieldnameTwo', 'fieldnameThree', 'fieldnameFour', 'fieldnameFive', ...]
Here is my server code...
app.post('/datasource/add', async (req, res) => {
const {datasourcename} = req.body;
const {datasourcefieldname} = req.body;
try {
const result = await session.run(
`Create(ds:DataSource {Title: $datasourcenameParam})
Create(dsf:DataSourceField {Title: $datasourcefieldnameParam})
Create (ds)-[:HAS_FIELD]->(dsf)
Set ds.date = apoc.date.format(timestamp(),"ms","MM/dd/yyyy"), ds.Uid = apoc.create.uuid() ,dsf.date = apoc.date.format(timestamp(),"ms","MM/dd/yyyy"), dsf.Uid = apoc.create.uuid()
Return ds,dsf`,
{datasourcenameParam:datasourcename, datasourcefieldnameParam: datasourcefieldname})
if (result) {
res.redirect('/gql');
console.log(datasourcename, datasourcefieldname);
session.close()
}
} catch (e) {
console.log("Something went wrong", e)
};
});
When I submit the data, data is created in Neo4j, but it's only creating 2 nodes: 1 ds:DataSource node and 1 dsf:DataSourceField node (the first one seen in the array) and then they are related as expected.
I don't know how to get my query to create all of the expected dsf:DataSrouceField nodes.
Thank you for any help you can provide.