Get Node by Property Value Neo4J

Get Node by Property Value Neo4J

How can i get node by propery value? I mean something like that: I'll tried

match (n) where has (n.name = 'Mark') return n

But it's incorrect.

And also How can i find node with max property value. I have nodes with property "VIEWS" and i want see node with max views.

1 Answer

So close...

MATCH (n) 
WHERE n.name = 'Mark' 
RETURN n

It is better to include a node label if you have one that will serve to segregate your node from other nodes of different types. This way if you have an index on the name property and label combination you will get better search responsiveness. For instance, you can create the index...

CREATE INDEX ON :Person(name)

And then query with the Person label.

MATCH (n:Person) 
WHERE n.name = 'Mark' 
RETURN n

Or alternatively you can query this way...

MATCH (n:Person {name:'Mark'}) 
RETURN n

To find the person with the most views...

MATCH (n:Person)
RETURN n, n.views
ORDER BY n.views desc
LIMIT 1

To find the most views without the person...

MATCH (n:Person)
RETURN max(n.views)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross
Author

Alexander Ross

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.