You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gremlin查询需求:筛选User指向当前Company的HasRight边

完善后的Gremlin查询及说明

需求说明

查询路径为:Company关联Employees关联User。需从User中筛选出所有指向当前遍历到的Company的HasRight边(该用户可能同时拥有其他公司的权限)。

完善后的完整查询

g.V()
.hasLabel("Company")
.as('company') // 标记当前Company节点,供后续过滤引用
.project("Company","Employees")
  .by(__.identity())
  .by(__.out("Has").hasLabel("Employee").not(__.has("IsDeleted",true)).has("Status",neq(5).and(neq(4)))
  .project("Employee","User","Rights")
    .by(__.identity())
    .by(__.out("Has").hasLabel("User"))
    .by(__.out("Has").hasLabel("User").outE("HasRight")
      // 完成TODO:过滤出指向当前Company的HasRight边
      .where(__.inV().is(__.select('company')))
    .fold())
  .fold())
.fold()

修改说明

  1. 标记当前Company节点:在.hasLabel("Company")后添加.as('company'),给当前遍历的Company节点设置引用标签,方便后续过滤逻辑调用。
  2. 精准过滤目标边:将原TODO处的.where(__.inV().hasLabel("Company"))替换为.where(__.inV().is(__.select('company'))),确保只筛选出当前User指向当前遍历的Company的HasRight边,而非任意Company的边。

内容的提问来源于stack exchange,提问作者uTILLIty

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 11:27:13