Gremlin 查询以在同一响应中检索计数和数据

Gremlin query to retrieve count and data in the same response

我正在寻求有关高效 gremlin 查询的帮助,其中 returns 数据采用预期格式。

数据结构:

g.V('user').property('id','1').property('name','name 1').property('city','city1')
g.V('user').property('id','2').property('name','name 2').property('city','city2')
g.V('user').property('id','3').property('name','name 3').property('city','city3')
g.V('user').property('id','4').property('name','name 4').property('city','city4')

预期输出:

{
  "count" : 4,
  "users : [
     { 
       "id" : "1",
       "name" : "name 1"
     },
     { 
       "id" : "2",
       "name" : "name 2"
     },
     { 
       "id" : "3",
       "name" : "name 3"
     },
     { 
       "id" : "4",
       "name" : "name 4"
     }
  ]
 }

非常感谢任何有关查询的帮助。

你可以试试:

g.V().hasLabel('user')
.project('id', 'name').by(id()).by(values('name')).fold()
.project('count', 'users').by(count(local)).by()