91
votes

I am using neo4j for one of my project, there's a node which only has a single property as name, I want to get that node using ID, it already has a ID but when I use this code

MATCH (s:SKILLS{ID:65110}) return s

It returns nothing, heres my node

enter image description here

If the query is wrong then how do I query it using the number

3
Which graph visualizing tool do you use ? Thanks. I know of yworks.com/neo4j-explorer good option for customization.MyUserInStackOverflow

3 Answers

148
votes
MATCH (s)
WHERE ID(s) = 65110
RETURN s

The ID function gets you the id of a node or relationship. This is different from any property called id or ID that you create.

13
votes

Warning: The following answer is incorrect! START should only be used when accessing legacy indexes. It is disabled in Cypher 2.2 and up.

Neo4j recommends using WHERE ID(n) = , and furthermore states that it will only require a single lookup (does not scan every node to find the matching ID)

Keeping this answer to prevent anyone from making the same mistake.

You can use WHERE ID(s) = 65110, but this will check the ID of every node in your database.

There is a more efficient way to do this:

START s=NODE(517) MATCH(s) RETURN s
4
votes

you can say:

(n:User) where id(n) >=20 RETURN n

this will return all nodes of type User with node reference ID more than 20