Jon Packer
Jon Packer

Reputation: 123

Exclude certain relationships from cypher query

I'm looking to make a cypher query which finds all outgoing relationships from node, excluding a couple. Here's an example:

START node=node(5), excludeRels=rel(7,8,9)
MATCH node-[rels]->x
RETURN rels

But I would like to exclude the rels in excludeRels from the returned rels. So if node(5) has outgoing relationships 6,7,8,9 and 10, I would like 6 and 10 to be returned.

Is this possible?

Upvotes: 1

Views: 1284

Answers (2)

Michael Hunger
Michael Hunger

Reputation: 41706

This should also work

START node=node(5), excludeRels=rel(7,8,9)
MATCH node-[rel]->()
WHERE rel <> excludeRels
RETURN rel

Upvotes: 0

Jon Packer
Jon Packer

Reputation: 123

Incase anyone else is wondering, I found the answer to the above problem to be:

START node=node(5), excludeRels=rel(7,8,9)
WITH node, collect(excludeRels) as erels
MATCH node-[rel]->()
WHERE NOT rel IN erels
RETURN rel

Upvotes: 3

Related Questions