My use case is that a current user of the system has access to a set of groups. These groups can belong to other groups. So I would like to get to all the base groups and the parent groups in one query.
g.V(currentUser)
.out("access-to")
.has(label, "groups")
.as("baseGrps")
.aggregate("baseGrps")
.until(out("belongs-to").count().is(0))
.repeat(out("belongs-to").simplePath().aggregate("grps"))
.cap("grps")
.unfold()
.dedup()
.as("nestedGrps")
.select("baseGrp", "nestedGrps")
However this is returning a map obviously, However I'd like to return just vertices so I can union in another traversal.
The seed sample data to run the above query against
g.addV("user")
.property("name", "AUser")
.as("aUser")
.addV("group")
.property("name", "UserGroup")
.as("userGroup")
.addV("userGroup")
.property("name", "AdminUserGroup")
.as("adminUserGroup")
.addV("group")
.property("name", "AllUserGroup")
.as("allUserGrp")
.select("aUser")
.addE("access-to")
.to("userGroup")
.select("userGroup")
.addE("belongs-to")
.to("adminUserGroup")
.select("adminUserGroup")
.addE("belongs-to")
.to("allUserGrp")
.select("aUser")
.next();
Any hints or improvements ideas will be really appreciated.
UPDATE: The below query is what seems to work for me. Not sure if its the best way.
g.V().has(T.label, "user").has("name", "AUser")
.union(
out("access-to")
.as("baseGroups")
.until(out("belongs-to").count().is(0))
.repeat(out("belongs-to").simplePath())
.emit()
.dedup()
.as("subGroups"),
out("access-to")
)
Mapand you say you want vertices but how do you want "baseGrp" and "nestedGrp" - all together? or should they remain separate? If you can explain the final result better, they may be ways to optimize your entire traversal to get your answer. - stephen malletteg.V(currentUser).union(<traversal returning all grps>, <another traversal returning a different set of grps>)- Sathyakumar Seshachalam