Deleting X nodes when there is no incoming Y nodes to them
Hello,
In my case, a
team
has many Member
and each member works only for one company. a company can also works for another company.
I want to delete all companies that no member of team works for them. In the following example company W and Z must be deleted but company Y should not. because member A works for X and X works for Y.
I wrote following query (and tried many other queries) but It delete all companies that does not have any direct member.
3 is the maximum depth of companies that can work with other companies.
I really appreciate your help1 Reply
Hello, you can try something like :
//select the team
g.V().has('team','name','backend').as("team")
//select the team's members
.out("member")
//select the companies that the members work for (and company of company...)
.repeat(out("work")).emit().times(3)
//aggregate that
.aggregate("worked")
//limit(1) to return to one traverser, select the team to restart with
.limit(1).select("team")
//go to the cooperating companies
out("cooperate").hasLabel("company")
// collect all the compagnies chained 3 times
.emit().repeat(out("work")).times(3)
//deduplicate (always in case of..)
.dedup()
//remove the comagnies thats your teams members works for and for
.where(without("worked"))
//and drop !
.drop()
Tell me if it works for you