Search code examples
gremlingraph-databases

Gremlin query with where has syntax error


I am using the gremlin console and I have the following Query: g.V().hasLabel("Account").where(in("Account").hasLabel("Opportunity").count().is(2))

groovysh_parse: 1: unexpected token: in @ line 1, column 33.
   g.V().hasLabel("Account").where(in("Account").hasLabel("Opportunity").count().is(2))
                                   ^

1 error

it should query all the vertices that are labeled as "Account" where which have more than 2 edges coming from vertices labeled as "Opportunity" however I get the following error in the gremlin console and I don't know why since even chatGPT says the syntax is ok


Solution

  • In Groovy (the Gremlin Console is based on the Groovy Console) in is a reserved word. Try using this instead:

    g.V().hasLabel("Account").
      where(__.in("Account").hasLabel("Opportunity").count().is(2))
    

    The __ (double underscore) class can be used to work around such reserved word conflicts. This is called an "anonymous traversal source".