I have 2 documents (Projects and Users) and 1 edge (is member to) where 1 User --is member to--> multiple Projects. I want to number of related Users to every Project, returning list of Project.name and count of users.
I'm able to get count but with document _ids and want to return the keys with Project.name:
for a in is_member_of
collect project = a._from into groups
sort count(groups) desc
return {"project": project, "membersInProject": count(groups)}
Returns:
project | membersInProject |
---|---|
Projects/6397 | 6 |
Projects/6398 | 4 |
Projects/6399 | 4 |
Projects/5999 | 2 |
I want project column to contain Project.name instead of Project._id
I found it:
FOR m IN is_member_to
FOR p IN Projects FILTER p._id == m._to
FOR u IN Users FILTER u._id == m._from
COLLECT x = p.name INTO groups
RETURN {"project": x, "count":COUNT(groups)}