Davina Leong
Davina Leong

Reputation: 767

Cypher query to get node by property not working

I'm building a Neo4j prototype in NodeJS.

I'm running a Cypher query on my local browser to test.

When I run this query, I get this:

MATCH (n) RETURN n;

screenshot of graph

But when I try to get a User by the id property, I get nothing.

This returns nothing

MATCH (u:User {id: 1}) RETURN u;

What am I doing wrong?

Eventually, I want to get the followers of a user using this:

MATCH (:User {id: 2})<-[:FOLLOWING]-(followers) RETURN followers.id;

Upvotes: 1

Views: 117

Answers (2)

jose_bacoy
jose_bacoy

Reputation: 12684

Try this query below. You need to put the value in quotes (string datatype) and remove duplicates when you return the id.

MATCH (:User {id: "2"})<-[:FOLLOWING]-(followers) 
RETURN distinct followers.id

Upvotes: 0

Dom Davis
Dom Davis

Reputation: 331

Most likely cause is that id is a string. MATCH (u:User {id: "1"}) RETURN u should work.

Upvotes: 1

Related Questions