0

I'm new to Janusgraph database. I have created a property key with cardinality as "LIST" and added that property to a vertex. Now I would like to retrieve individual value of that vertex's property. Currently I'm getting entire list as a string.

youtubeUrls = graph.makePropertyKey('youturls').dataType(String.class).cardinality(Cardinality.LIST).make()
urls = graph.addVertex(T.label, 'urls', 'youturls', ["google.com", "yahoo.com", "geekbull.in"])

I am not able to get the first value from the list. I tried so many ways like below,

g.V(urls).values('youturls')[0]

But I'm getting entire list as one string. Where am I doing mistake? Any suggestions and solutions are highly appreciated.

Shr4N
  • 435
  • 3
  • 18

1 Answers1

2

The way you add the values is wrong, you need to add each String separately.

g.addV('url').
    property(list, 'youturls', 'google.com').
    property(list, 'youturls', 'yahoo.com').
    property(list, 'youturls', 'geekbull.in').iterate()

Then, when it comes to querying, you can access a specific value like this:

gremlin> g.V().map(values('youturls').range(0,1))
==>google.com
gremlin> g.V().map(values('youturls').range(1,2))
==>yahoo.com
gremlin> g.V().map(values('youturls').range(2,3))
==>geekbull.in
Daniel Kuppitz
  • 10,846
  • 1
  • 25
  • 34