node.jsgremlintinkerpop

How is select being used outside a traversal? groovy gremlin vs nodejs gremlin


I found this QA to be very useful, or at least would be if I understood what the heck is going on, and could translate it from groovy gremlin to nodejs gremlin. What's tripping me up is the use of the select function. For example, the answerer writes:

g.V(4).as('source').
  addV().
    property(label, select('source').label())

Now, I obviously can't just ctrl+v ctrl+p into my nodejs code, because it would interpret select as some function that is as of yet undefined (and label as well is undefined).

But I doubt this is a matter of just importing select, because well... I've never seen select on it's own outside of a traversal. Nor do the tinkerpop docs give any examples like that. select is always on the chain of functions, like g.addV().as('x').select('x') or something like that. So what is going on? and more importantly, how do I translate it into nodejs?


Solution

  • Likely what you're missing is the anonymous traversal (__). It is one of the common imports: https://tinkerpop.apache.org/docs/current/reference/#gremlin-javascript-imports

    So the query would be written as:

    g.V(4).as('source').
      addV().
        property(label, __.select('source').label())
    

    Do a search for "anonymous" in Kelvin's book and it explains it, to some extent: https://kelvinlawrence.net/book/Gremlin-Graph-Guide.html