Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-26-2022 02:50 PM
size((n)<--())
If the above is depreciated so what's the best Cypher way in 4.4.4 to know the number of inbound or outbound relationships for a node?
03-27-2022 01:19 AM
How would you use count() to count the number of inbound relationships for a given node instead of counting the number of nodes itself which is I think two completly different things.
Counter the number of relationships for a node seems to be way faster to me than traversing the nodes connected then count them.
03-27-2022 04:33 AM
Where did you see that feature was deprecated in 4.4.4? I look at the list of deprecated features for 4.4.4 and did not see it. It is also listed on the latest cypher reference card.
04-02-2022 02:58 AM
The neo4j desktop shows up a warning when you use size with a pattern.
03-27-2022 06:05 AM
It looks like the future syntax will be something like this:
MATCH (a)
RETURN size([(a)-->(b) | 1]) AS years
Regards,
Cobra
04-02-2022 09:00 AM
yeah, I see that now. Your question is good. It was very logical and compact notation. You can use the pattern comprehension, as noted by @bennu.neo, or a subquery (which is very verbose), or an optional match, as below. Each of these solutions seems a little convoluted compared to size(pattern).
match(n:Item{key:340})
optional match (n)-->(r)
return n, count(r) as outCount
Any other ideas?
04-03-2022 12:26 PM
OPTIONAL MATCH doesn't count the number of in and/or out relationships from a node, it actually traverse each node connected to it and generate rows per connected node which is way slower than size().
04-03-2022 12:29 PM
I think Neo4j should reconsider using size for pattern as it's the most straighforward way to count the number of in or out relation's type.
04-03-2022 03:59 PM
I agree..It is very intuitive, straightforward, and direct. The other methods proposed seem like workarounds and indirectly figure it out.
All the sessions of the conference are now available online