Shukaku
(Shukaku G)
October 14, 2020, 5:41am
1
So here's my dilemma...
I want to be able to find distinct pairs of node with some value (a: nodeA {number: 1}), that are found in node (b)
by distinct pairs I mean:
1,2
3,4
and not:
1,2
2,1
I'm just looking for the proper syntax so I can implement it in my code.
cobra
(Cobra)
October 14, 2020, 6:29am
2
Hello @Shukaku
This is a way of doing this, with APOC you can also sort list of nodes if you need more data from them:
WITH [[1,2], [2,1], [3,4], [4,3], [5,6]] AS list
UNWIND list AS items
WITH apoc.coll.sort(items) AS items_sort, collect(items)[0] AS items_list
RETURN items_list
Regards,
Cobra
Shukaku
(Shukaku G)
October 14, 2020, 7:23pm
3
What if I'm unable to call apoc.coll.sort? is there an alternative to that?
cobra
(Cobra)
October 14, 2020, 7:34pm
4
To be honest, I'm curious if you find something only in Cypher I had this problem a few days ago and I only found this solution with APOC.
For distinct node pairs, once you have the variables for both nodes, you can use the following to get rid of mirrored results:
...
WITH n1, n2
WHERE id(n1) < id(n2)
...
1 Like
Shukaku
(Shukaku G)
October 15, 2020, 1:50am
6
Thank you @andrew_bowman and @cobra !
Andrew's answer is what I was looking for.
1 Like