Hi guys i'm new in Gremlin and Graph DB (sorry in front for any trivial questions).
In my project i post request has URI that looks like this: /NodeName1/NodeName2/NodeName3/.... (Node1 has edge to Node2, Node2 to Node3, etc).
And i need to get to the last one node in that uri, but I never know how long that uri will be so i came up with idea to chain methods has('name', '...').out() after i split that uri and count nodes in that uri.
Query would look like this:
g.V().has('name', "NodeName1").out().has('name',"NodeName2").out()....
For that i will use _query variable and than chain methods on that variable. But there is problem. _query is type GraphTraversal<S,E> which is generic type and i dont know what types i need to set, but because g.V() returns GraphTraversal<Vertex,Vertex> i set that, but when i want to execute something like this:
var result = _query.has('name', "NodeName1").out().id().Next();
I get error that says "Cant convert int64 to Gremlin.Vertex". When i remove id() it will return type Vertex and i can get id with
result.id (but that's not what i want).
This is my code:
protected GraphTraversalSource g;
protected GraphTraversal<Vertex,Vertex> _query;
public GremlinTest(string rootId = null)
{
g = Traversal().WithRemote(_remoteConnection);
_query = !string.IsNullOrEmpty(rootId) ? g.V(rootId) : g.V();
}
public void AddVertex(string name)
{
_query.has("name", name).out();
}
public void GetId()
{
_
query.id();
}
public "What return type?" Execute()
{
return _query.Next() or _query.ToList() or _query.Iterate();
}
I also want to create query that will get me property of all nodes that are connected with last node in URI. I came up with something like this: But again i'm not sure about returning type and if it's good.
g.V().has('name', "NodeName1").out().has('name',"NodeName2").out()....has('name', "LastNode").Repeat(Out().SimplePath()).Until(Label().Is("Something")).ValueMap<string, object>(true);
Hope i explained what i have trouble with. Also I will answer any of your question as soon as i can.
Thank you in front guys Stefan.