如何将列表中的每个元素包装到一个对象中?

How do I wrap each element in the list into an object?

我有以下 gremlin 查询,我在其中查询多条边,然后查询它们的伴随顶点

     outE('childSolution')
                .inV()
                .local(union(
                     identity()
                     .valueMap(true)
                     .project('solution')
                    ,
                     outE('writtenBy')
                    .inV()
                    .valueMap(true)
                    .project('originator')
                    , 
                    outE('childProblem')
                    .inV()
                    .valueMap(true)
                    .project('childProblem')
                ))
                .fold()
                .project('childSolutions')

我回来了

    "childSolutions": [
          { "solution" : { properties... }
          },
          {
            "originator": { properties... }
          }
     ]

我想要的是

"childSolutions": [
        { "fullSolution : {
          { "solution" : { properties... }
          },
          {
            "originator": { properties... }
          }
         },
        { "fullSolution : {
          { "solution" : { properties... }
          },
          {
            "originator": { properties... }
          }
         }
     ]

如有任何帮助,我们将不胜感激

在询问有关 Gremlin 的问题时,最好始终提供可以生成示例图的 Gremlin 脚本,以便将其粘贴到 Gremlin 控制台会话中。这样那些回答的人就可以测试他们的结果。在这种情况下,我只是轻扫一下重写你的遍历,但我认为你需要反转你使用 project() 的方式,你会得到一个更具可读性的遍历,并且可以做你想做的事情:

out('childSolution').
project('childSolutions').
  by(project('solution','originator','childProblem')
       by(valueMap(true)).
       by(out('writtenBy').valueMap(true)) 
       by(out('childProblem').valueMap(true)))

使用 project() 您可以预先指定您想要的键是什么,然后使用 by() 来说明这些键中应该包含什么。这个遍历的输出并不完全符合你想要的,但我想我在精神上是正确的。如果您希望它完全匹配,那么最好在您的问题中提供示例图表。