Search code examples
datastaxgremlingraphdb

Gremlin : Check for vertex existence if yes than proceed for further travelsal


Is there a way to do the below use case in our single query.

  1. Check for a vertex for its existence with some id.
  2. If exists then do the further traversals.

Currently, we are doing the above using two queries.


Solution

  • You shouldn't have to do anything special if your only choice is to proceed if the element exists. In other words, if you have:

    g.V(1).out()
    

    If a vertex with id of "1" is not present, it will simply not traverse out() as none exists. If you have a need for alternative processing in the event that the vertex does NOT exist then you will need to use some form of branching logic (typically coalesce() or choose()). Here's some examples of element existence checks which demonstrate "get or create" types of operations that might be applicable to what you're doing.