gremwell
gremwell

Reputation: 1457

Neo4j cypher with parameters returns success but doesn't create anything?

If I send this:

{
  "query" :  "MATCH (p) WHERE p.id={id} CREATE (c {props}) CREATE UNIQUE p-[r:CHILD]->c",
  "params" : {  
      "id" : ["{0000-0000-0000-0000}","{0000-0000-0000-0000}","{0000-0000-0000-0004}"],
      "props" : [ {
          "id" : "{0000-0000-0000-0004}",
          "type": 48,
          "title" : "TestNode" 
       },{
          "id" : "{0000-0000-0000-0005}",
          "type": 49,
          "title" : "TestNode"
       },{
          "id" : "{0000-0000-0000-0006}",
          "type": 49,
          "title" : "TestNode"
       }]
   }
}

Via the restful cypher api, I get back "success" but nothing was created. If I send through this:

{
  "query" :  "MATCH (p) WHERE p.id={id} CREATE (c {props}) CREATE UNIQUE p-[r:CHILD]->c",
  "params" : {  
    "id" : "{0000-0000-0000-0000}",
    "props" : [ {
        "id" : "{0000-0000-0000-0001}",
        "type": 48,
        "title" : "TestNode"
    },{
        "id" : "{0000-0000-0000-0002}",
        "type": 49,
        "title" : "TestNode"
    } ]
  }
}

It creates two children of 0000-0000-0000-0000 as expected. So something about the way I'm specifying two arrays isn't working.

I was hoping to be able to create large tree structures by essentially specifying parent ID/child to create parameters. The other option is that I use the latter style cypher and the transactional endpoint... but I'm just not sure what I'm doing wrong in the first one. Any advice much appreciated.

Upvotes: 0

Views: 76

Answers (1)

Eve Freeman
Eve Freeman

Reputation: 33175

You probably need to do:

MATCH (p) WHERE p.id IN {id}
CREATE (c {props}) 
CREATE UNIQUE (p)-[r:CHILD]->(c)

The = operator is an exact comparison.

Upvotes: 2

Related Questions