Joel Stevick
Joel Stevick

Reputation: 2038

neo4j: What is the syntax to set cypher query parameters in the browser interface?

I am trying to run queries from the neo4j browser to reproduce results from my neo4j-javascript-driver client.

What is the syntax for defining query parameters in the neo4j b

I recently attended a neo4j training session in NYC where the trainer (David Fauth) did this, unfortunately, I did not take notes on it, since I figured that I could read-up on this online...but no success.

Upvotes: 32

Views: 20864

Answers (5)

stdob--
stdob--

Reputation: 29172

In neo4j-browser you need type for example:

:params {nodes: [{name: "John", age: 18}, {name: "Phill", age: 23}]}

Then you can use params as usual:

UNWIND {nodes} as node
MERGE (A:User {name: node.name, age: node.age})
RETURN A

For clear params in neo4j-browser type :params {}.

For additional help type :help params.

Upvotes: 52

Juha M
Juha M

Reputation: 500

The basic cases:

  1. Set singe variable value mytext="Hello": :param mytext => "Hello"
  2. set dictionary values attr={"oid":1, "text":"Hello"}: :param attr => ({oid: 1, text:"Hello"})

Cypher usage:

  1. MATCH (x) WHERE x.a = $mytext RETURN x
  2. set a value MATCH (x) WHERE x.a = $attr.oid SET x.b = $attr.text
  3. set multiple values MATCH (x) WHERE ... SET x = $attr

Upvotes: 0

Dima Korobskiy
Dima Korobskiy

Reputation: 1556

In Neo4j Browser 3.5+ you can use the Cypher Shell parameter syntax, documented here: https://neo4j.com/docs/operations-manual/3.5/tools/cypher-shell/#cypher-shell-parameters

:param name => expression

The expression must be kept on a single line.

The expression could be a scalar or a list:

:param foo => ['a', 'b', 'c']

Maps can't be used directly with this syntax as of Neo4j 4.1. You can wrap them into a list:

:param foo => [{name: 'Alice', age: 38, address: {city: 'London', residential: true}}] 

Or you can use :params:

:params {foo: {name: 'Alice', age: 38, address: {city: 'London', residential: true}}}

Upvotes: 3

konstantin shevchenko
konstantin shevchenko

Reputation: 61

In Neo4j Browser 3.5+ you can use

:params param_name => 'param_value'

Upvotes: 0

Mr.QA
Mr.QA

Reputation: 101

In Neo4j-3.3.4, the cypher likes this:

:param nodes: [{name: 'John', age: 18}, {name: 'Phill', age: 23}]

Neo4j Browser result: here

Upvotes: 10

Related Questions