3

I'm trying to return a specific node with the id (using neo4j-driver package within my nodejs server). I have the id of the node I'm searching for. So I used the parameters in the run method as showed bellow but I'm not getting any nodes.

session.run('MATCH (n:User)-[:OWN]->(a) WHERE id(n) = $id RETURN a',{id: idUser})

I checked and idUser-value is 128 and when i'm running this command, I get the right node.

session.run('MATCH (n:User)-[:OWN]->(a) WHERE id(n) = 128 RETURN a',{id: idUser})

Is there any one to make the first command working so I can get the node of the given id ?

Thanks

Nelands
  • 33
  • 3
  • 2
    Perhaps `idUser1` has a string value? The native ID has a numeric value, and the comparison will always fail if you try to compare it with a string. – cybersam Jul 02 '18 at 20:23

1 Answers1

3

As it is written in the driver documentation:

Number written directly e.g. session.run("CREATE (n:Node {age: {age}})", {age: 22}) will be of type Float in Neo4j. To write the age as an integer the neo4j.int method should be used... https://github.com/neo4j/neo4j-javascript-driver#write-integers

So when you pass the identifier from the node.js, you need to convert it:

session
  .run('MATCH (n:User)-[:OWN]->(a) WHERE id(n) = $id RETURN a', {
    id: neo4j.int(idUser)
  })

or:

session
  .run('MATCH (n:User)-[:OWN]->(a) WHERE id(n) = toInteger($id) RETURN a', {
    id: idUser
  })
stdob--
  • 28,222
  • 5
  • 58
  • 73