whitfa
whitfa

Reputation: 117

How to use parameters correctly in Transactional Cypher HTTP

I'm a bit stuck. I'm trying to use parameters in my http request in order to reduce the overhead but I just can't figure out why this won't work:

{
"statements" : [ {
"statement" : "MATCH (n:Person) WHERE n.name = {name}  SET n.dogs={dogs}   RETURN n",
"parameters" : [{

"name" : "Andres",
"dogs":5
},{

"name" : "Michael",
"dogs":3
},{

"name" : "Someone",
"dogs":2
}
]

}]
}

I've tried just opening a transaction with a STATEMENT and feeding the separate 'rows' in as PARAMETERS on subsequent transactions before I /COMMIT, but no joy.

I know that multiple nodes can be created in a similar from the examples in the manual.

What am I missing?

Upvotes: 1

Views: 175

Answers (2)

Christophe Willemsen
Christophe Willemsen

Reputation: 20185

You can also use UNWIND for this case :

The statement :

UNWIND props as prop
MERGE (user:People {id: {prop}.id}) // and the rest of your query

The parameters :

{"props":[ {"id": 1234, "name": "John"},{"id": 4567, "name": "Chris"}]}

This is what is used on Graphgen to load the generated graphs in a local database from the webapp. http://graphgen.neoxygen.io

Upvotes: 0

whitfa
whitfa

Reputation: 117

I've since modified an answer from this post, which seems to work by using a FOREACH statement to allow for multplie 'sets' of parameters.

{
  "statements" : [ 

  {
"parameters": {
    "props": [
        {
            "userid": "177032492760",
            "username": "John"
        },
        {
            "userid": "177032492760",
            "username": "Mike"
        },
        {
            "userid": "100007496328",
            "username": "Wilber"
        }
    ]
},
"statement": "FOREACH (p in {props} | MERGE (user:People {id:p.userid}) ON CREATE SET user.name = p.username) "
}
]
}

Upvotes: 2

Related Questions