Hi,
collect is just an aggregation function, like count() and sum() etc.
It will turn any expression into a list of values.
In this case, the expression is the map, and the syntax for maps is the
same as for JSON/JavaScript objects.
you would have the same if you separate it out
WITH g, {person: person.GivenName, role: role.Role} as personData
RETURN g, collect(personData) as people
So for your example, you just missed the new key (or in the 2nd case
overrode it)
RETURN g, collect( { givenName: person.GivenName, familyName:
person.FamilyName, role: role.Role} )
If your inline map expression gets too complex I recommend to separate it
out as I showed before.
Michael
On Tue, Jan 10, 2017 at 1:24 AM, David Rader <[email protected]> wrote:
> Michael,
> Once again, you've got a GREAT answer. Thanks.
>
> I had not seen the [role:LEADS|:ADMtINISTERS|:MEMBER_OF] use of multiple
> labels in a pattern before. VERY helpful and confirms (yea) the design
> decision to use a couple different relationship labels.
> I tested with different combinations and received the expected responses.
>
> On the alternative RETURN statement (with two clauses in the collect()
> function), I tried to insert a third clause.
> The form you supplied worked as expected. However, person has two names:
> GivenName and FamilyName (a few have a PreferredName for nick names or use
> of a middle name).
> When I tried collect(person: person.GivenName, role: role.Role) the
> response was exactly as expected.
> When I tried collect(person: person.GivenName, person.FamilyName, role:
> role.Role) I received an error starting at the second use of the variable
> person.
> When I tried collect(person: person.GivenName, person: person.FamilyName,
> role: role.Role) the response was the FamilyName and Role but not the
> GivenName.
> What is the syntax for additional properties from the same node?
>
> This is refining my understanding of collect(). The actual query I used
> does not have collect which returns each person as a separate row for easy
> ORDER BY for a directory by name and by org.
>
> Many thanks
> Dave
>
> On Monday, January 9, 2017 at 1:14:22 AM UTC-8, Michael Hunger wrote:
>>
>> Hi Dave
>>
>> you can also join neo4j.com/slack and ask your questions there :) you
>> might get some faster answers:
>>
>> I could imagine something like this:
>>
>> MATCH (r:Organization)<-[:PART_OF*0..3]-(part)
>> MATCH (part)-[role:LEADS|:ADMINISTERS|:MEMBER_OF]-(person:Person)
>> RETURN part, collect(person) as members
>>
>> or
>>
>> RETURN part, collect({person: person, role:type(role)}) as members
>>
>> On Mon, Jan 9, 2017 at 2:05 AM, David Rader <[email protected]> wrote:
>>
>>> I have an organization with departments and sub-departments. People are
>>> assigned (relationships) at each level.
>>> What is the query pattern that gives the members of each organization
>>> level by level?
>>> There are three relationship types: :LEADS, :ADMINISTERS, and
>>> :MEMBER_OF. Is there a way to exclude one of the relationship types?
>>>
>>> My best attempt generated tons of redundancy.
>>> Not sure whether it is best to try to collect at each level or use some
>>> other construct to walk the tree.
>>>
>>> BTW, what is best practice for managers - members of the department they
>>> supervise or member of the (higher level) group of people managed by their
>>> boss?
>>>
>>> Thanks
>>> Dave (a recovering relational database user)
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Neo4j" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Neo4j" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.