0

How to check whether a node exists using relationship and other node of the relationship?

 A ->(IN) B

I want to check if B is present with node A having relationship IN using py2neo

I tried this cypher query:

MATCH (a { name:'xyz' })<-[:IN]-(b)
Return b

But I was looking for something in py2neo like find function?

blackmamba
  • 1,952
  • 11
  • 34
  • 59
  • Are you using cypher? what are your labels? what's the context? what have you tried (as Stefan already said). You should take a look at this: http://stackoverflow.com/help/how-to-ask – Supamiu Dec 10 '15 at 09:11

2 Answers2

0

I'll assume you are using cypher, so you should try this:

OPTIONAL Match (A:Foo)-[:IN]->(B:Bar)
return RETURN B IS NOT NULL AS exists

Using case allows you to return a boolean based on the existence of B using an optional match.

Supamiu
  • 8,501
  • 7
  • 42
  • 76
0

You can use the py2neo function match-one() (documented on this page). It will return one such relationship, should any exist.

If you want to see all such relationships, you can use the match() function instead.

cybersam
  • 63,203
  • 6
  • 53
  • 76