1

I need to create vertices without duplication based on a list passed to inject(), the list is very large so I need to use inject(). I tried this but it didn't work:

g.inject(["Macka", "Pedro", "Albert"]).unfold().map(
    coalesce(
        V().has("name", identity()),
        addV("user").property("name", identity())
    )
)

You can try here: https://gremlify.com/765qiupxinw

Why this doesn't work? It seems that V().has() is returning all vertices, why?

fermmm
  • 1,078
  • 1
  • 9
  • 17

1 Answers1

1

I think in this case you should use where step and not has:

g.inject(["Macka", "Pedro", "Albert"]).unfold().as('n').map(
    coalesce(
        V().where(eq('n')).by('name').by(),
        addV("user").property("name", identity())
    )
)

example: https://gremlify.com/06q0zxgd2uam

noam621
  • 2,766
  • 1
  • 16
  • 26
  • 4
    `has(String,Traversal)` doesn't do what most people think it does. this version of `has()` is meant to evaluate the anonymous `Traversal` as a filter using the current property value as the traverser. it does not resolve the `Traversal` to a value to use it as the object of the `has()`. some discussion here: https://issues.apache.org/jira/browse/TINKERPOP-1463 – stephen mallette Sep 28 '20 at 10:39
  • 2
    Is this a good alternative? ```V().has("name", where(eq("n")))``` I find it a little bit more readable and seems to be working – fermmm Sep 28 '20 at 15:54