I'm new to Gremlin and CosmosDB. I've been following the tinkerpop tutorials and am using the TinkerFactory.createModern() test graph.
What I am looking for is to return a graphson object similar to this from cosmosdb.
{
"user": {
"name": "Marko",
"age": 29
},
"knows": [
{"name": "josh", "age": 32},
{"name": "vadas", "age": 27}
],
"created": [
{"name": "lop", "lang": "java"}
]
}
My thoughts were to try
g.V().has('name', 'marko').as('user').out('knows').as('knows').out('created').as('created').select('user', 'knows', 'created')
What i really get back is in the picture below. I was hoping to have single user object, with an array of knows objects and software objects.
If this is possible can you please explain what steps need to be used to get this format.
Hope my question is clear and thanks to anyone that can help =)
You should use project()
:
gremlin> g.V().has('person','name','marko').
......1> project('user','knows','created').
......2> by(project('name','age').by('name').by('age')).
......3> by(out('knows').project('name','age').by('name').by('age')).
......4> by(out('created').project('name','lang').by('name').by('lang'))
==>[user:[name:marko,age:29],knows:[name:vadas,age:27],created:[name:lop,lang:java]]
That syntax should work with CosmosDB. In TinkerPop 3.4.0, things get a little nicer as you can use valueMap()
a bit more effectively (but I don't think that CosmosDB supports that as of the time of this answer):
gremlin> g.V().has('person','name','marko').
......1> project('user','knows','created').
......2> by(valueMap('name','age').by(unfold())).
......3> by(out('knows').valueMap('name','age').by(unfold())).
......4> by(out('created').valueMap('name','lang').by(unfold()))
==>[user:[name:marko,age:29],knows:[name:vadas,age:27],created:[name:lop,lang:java]]