Neo4j- How can I match by using the internal ID

78 views Asked by At

I need to retrieve a node in Neo4j and I only have the internal ID.

Is there a way to retrieve the node that has the ID in the given set in one cypher query ?

I'm using Neo4j 2.1.5

Thanks !

from neomodel import db
query="MATCH (n:Message) WHERE ID(n)="+id+" SET n.type='"+str(ans)+"', n.reprimands='"+str(ans2)+"'"
db.cypher_query(query)

I tried this but it didn't work out. I asigned the id in the python code, but it didn't seemed to have matched the ID I already had in my neo4j db. I used SET to change some attributes in the db but nothing changed at all.

I am using neomodel to access the DB via python.

1

There are 1 answers

3
B D T On

I think it's because you have ID capitalized.

Also, it looks like you're naming the python variable with id. That's already a python function, so I'd recommend naming the variable something like databaseId. You code would become...

from neomodel import db
query="MATCH (n:Message) WHERE id(n)="+databaseId+" SET n.type='"+str(ans)+"', n.reprimands='"+str(ans2)+"'"
db.cypher_query(query)

The cypher would look something like this:

MATCH (n:Message)
  WHERE id(n) = 123
SET n.type = "some type",
    n.reprimands = "some reprimands"