Search code examples
gremlintinkerpop3

Gremlin-Python: Property existence check


I can't seem to figure out an idiomatic way to filter nodes that have or don't have a certain property (regardless of its value).

Property exists:

> g.V().hasNot('weight', None).toList()
*** gremlin_python.driver.protocol.GremlinServerError: 599: Could not locate method: DefaultGraphTraversal.hasNot([weight, null])

Property doesn't exist:

> g.V().has('weight', None).toList()
*** gremlin_python.driver.protocol.GremlinServerError: 599: null:has([weight, null])

hasKey() returns no results:

> g.V().hasKey('weight')

Using gremlin-server 3.3.4


Solution

  • Oh, turns out this works:

    g.V().has('weight')
    

    It was just hard to find in the docs: http://tinkerpop.apache.org/docs/current/reference/#has-step