cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Match relationships if a certain parameter exists

Hello,

I've been using neo4j for a while and recently i got stuck with a query that i don't seem to be able to succesfully run.

My goal: I have a type of relationship called HAS_RELATIONSHIP. this type of rel sometimes have a property called verified. I want to get a subgraph of those relationships that don't have this property so i can afterwards add the property.

What I have done so far:

Match (a)-[r:HAS_RELATIONSHIP]-(b) 
where  r.verified=False 
set r.verified=True
LIMIT 5
return r, r1, a, b

the part that is not working is where r.verified=False it should be something like exists(r)=verified but t doesn't seem to exist this kind of query. I have checked on OPTIONAL MATCH, but it seems it is neither the solution.

Any ideas?

1 ACCEPTED SOLUTION

Hello @alvaro.lloret.demull and welcome to the Neo4j community

MATCH (a)-[r:HAS_RELATIONSHIP]-(b) 
WHERE NOT EXISTS(r.verified) 
SET r.verified = True
LIMIT 5
RETURN r, r1, a, b

OR

MATCH (a)-[r:HAS_RELATIONSHIP]-(b) 
WHERE r.verified IS NULL 
SET r.verified = True
LIMIT 5
RETURN r, r1, a, b

Regards,
Cobra

View solution in original post

2 REPLIES 2

Hello @alvaro.lloret.demull and welcome to the Neo4j community

MATCH (a)-[r:HAS_RELATIONSHIP]-(b) 
WHERE NOT EXISTS(r.verified) 
SET r.verified = True
LIMIT 5
RETURN r, r1, a, b

OR

MATCH (a)-[r:HAS_RELATIONSHIP]-(b) 
WHERE r.verified IS NULL 
SET r.verified = True
LIMIT 5
RETURN r, r1, a, b

Regards,
Cobra

Thanks! This was it!