1
votes

I am new to neo4j and neo4jclient so please excuse if my question is not on the right track.

With mutating cypher queries it is possible to create multiple nodes and relationships in one call. I want to create a query similar to the movie example data that comes with neo4j so that it creates multiple nodes and relationships in one post to the REST API.

Is it possible to write a query like this using neo4jclinet?

I've had a look at the documentation below but I couldn't see an example of the type of query I was after. Im quite new to this so perhaps I missed it.

https://github.com/Readify/Neo4jClient/wiki/cypher-examples

1

1 Answers

1
votes

Usually there are two ways of doing this. First is to use batch with multiple queries, which isn't supported by the neo4jclient. Looking at the source code shows that there is some kind of batch support (like the GraphClient.ExecuteBatch method), but those are private.

The second is to build a Cypher query by adding each node as a parameter, which should result in request as described here. The code would look like this:

var queryBuilder = client.Cypher.
    Create ("(movie:Movide {newMovie})");

foreach (Movie movie in movies) {
    queryBuilder = queryBuilder.WithParam ("newMovie", movie);
}

queryBuilder.ExecuteWithoutResults ()

This however throws an ArgumentException: "A parameter with the given key is already defined in the query." if there is more then one element on the list.

So you are probably stuck with one of those nasty workarounds:

  1. building a query with multiple (indexed) parameters
  2. executing one query for one node
  3. a manual query, which is discouraged.

This seems to me like an issue worth reporting to Readify.