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?

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

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

1 Like

Thanks! This was it!

1 Like