Reputation: 2238
I have a bunch of Foo
objects in my graph, and they may have 0 to n related Bar
objects. Bar
objects have a property I'm looking to aggregate against, baz
. Here's what I've started with:
MATCH (f:Foo)--(b:Bar) RETURN f, COLLECT(b.baz)
I'm trying to get output that looks like the following:
===============================
| f | COLLECT(b.baz) |
-------------------------------
| Node(1..) | ["1", "2", "3"] |
| Node(2..) | ["4", "5"] |
===============================
Instead, I'm getting what looks like this:
===============================
| f | COLLECT(b.baz) |
-------------------------------
| Node(1..) | ["1"] |
| Node(1..) | ["2"] |
| etc... |
===============================
Any insight as to what I'm doing wrong?
Upvotes: 0
Views: 890
Reputation: 5047
Can you create an example dataset? For this dataset your query works fine.
CREATE
(n1:Foo {name: '1'}),
(a:Bar {name: 'a', baz: 1}),
(b:Bar {name: 'b', baz: 2}),
(n1)-[:REL]->(a),
(n1)-[:REL]->(b)
Your query returns the following:
MATCH (f:Foo)--(b:Bar)
RETURN f, COLLECT(b.baz)
╒═════════╤══════════════╕
│f │COLLECT(b.baz)│
╞═════════╪══════════════╡
│{name: 1}│[1, 2] │
└─────────┴──────────────┘
Upvotes: 2