I have many nodes and edges in a list. Currently I'm looping through the list and inserting each node with a query which is very slow. How do I perform a batch insert using neo4jclient?
Node object:
public class myNode
{
public int id { get; set; }
public int floor { get; set; }
public double x { get; set; }
public double y { get; set; }
}
Current method for inserting a node:
public static void addNode(GraphClient client, myNode node, string nodeName)
{
client.Cypher
.Create("(" + nodeName + ":Node {node})")
.WithParams(new { node })
.ExecuteWithoutResults();
}
Current method for inserting List of nodes:
List<myNode> nodeList;
foreach(var elem in nodeList)
addNode(client, elem, "foo");
Instead of just passing a single node into your Cypher, you could pass in the collection. According to the Neo4j manual
See the section Create multiple nodes with a parameter for their properties in the Neo4j Manual v2.2.2.
Therefore your C# code will become simplified and should perform better.
Hope that helps.