Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use parameters with neo4j?

Tags:

neo4j

I am looking at the documentation for neo4j and I see that I can use parameters when I create objects. Specifically when I look at this page I see the code:

{
  "props" : {
    "position" : "Developer",
    "name" : "Andres"
  }
}

Query.

CREATE ({ props })

Yet when I use the web interface to access my neo4j database on my local machine I do not know how to specify the parameter. Simply copy/pasting that JSON object yields an error. I see on the page that

Exactly how to submit them depends on the driver in use.

but how does one use them on that command line/web interface?

like image 308
WildBill Avatar asked Mar 09 '14 00:03

WildBill


1 Answers

Cypher supports queries with parameters which are submitted as JSON. For example, the following is the REST API usage. For the Java embedded API please refer to the following documentation: http://docs.neo4j.org/chunked/milestone/tutorials-cypher-parameters-java.html

MATCH (x { name: { startName }})-[r]-(friend)
WHERE friend.name = { name }
RETURN TYPE(r)

Example request

POST http://localhost:7474/db/data/cypher
Accept: application/json; charset=UTF-8
Content-Type: application/json 

{
  "query" : "MATCH (x {name: {startName}})-[r]-(friend) WHERE friend.name = {name} RETURN TYPE(r)",
  "params" : {
    "startName" : "I",
    "name" : "you"
  }
}

Example response

200: OK
Content-Type: application/json; charset=UTF-8

{
  "columns" : [ "TYPE(r)" ],
  "data" : [ [ "know" ] ]
}

Parameters are not currently supported in regular Cypher statements in the Neo4j 2.0 browser. However, you can use the :POST syntax to achieve this.

Refer to the documentation for more information on Cypher queries via REST API.

http://docs.neo4j.org/chunked/milestone/rest-api-cypher.html

Update:

The following query allows you to accomplish this in the browser, although it is not an ideal experience:

:POST /db/data/transaction/commit {
    "statements": [
        {
            "statement": "MATCH (u:User {name:{username}}) RETURN u.name as username",
            "parameters": {
                "username": "my name"
            }
        }
    ]
}
like image 180
Kenny Bastani Avatar answered Sep 29 '22 15:09

Kenny Bastani