I am looking for help with an efficient gremlin query which returns data in the expected format.
Data structure :
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')
Expected output:
{
"count" : 4,
"users : [
{
"id" : "1",
"name" : "name 1"
},
{
"id" : "2",
"name" : "name 2"
},
{
"id" : "3",
"name" : "name 3"
},
{
"id" : "4",
"name" : "name 4"
}
]
}
Any help with the query is highly appreciated.
You can try:
g.V().hasLabel('user')
.project('id', 'name').by(id()).by(values('name')).fold()
.project('count', 'users').by(count(local)).by()