我尝试运行下面的查询:
edge = g.V(id).addE("rated").to(g.V(n_id)).next()
但我收到错误
InvalidRequest: Error from server: code=2200 [Invalid query] message="Could not read the traversal from the request sent. Error was: Could not locate method: DefaultGraphTraversal.addE([rated, [GraphStep(vertex,[{source_id=34897306, source_system=MSI_CLIENT, ~label=person}])]])"
g.V(id)
和g.V(n_id)
都返回顶点,我没有看到任何问题。有人可以告诉我为什么我会遇到上述错误吗?
gremlinpython 有一个怪癖,它阻止您以这种方式将遍历嵌套在其他遍历中。当您在遍历中嵌套
V()
时,必须使用 __
类,如下所示:__.V()
。您可以将 __
类导入为 from gremlin_python.process.graph_traversal import __
。
下面的代码应该可以工作:
from gremlin_python.process.anonymous_traversal import traversal
from gremlin_python.process.graph_traversal import __, GraphTraversalSource
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
g: GraphTraversalSource = traversal().withRemote(
DriverRemoteConnection(GRAPH_DB_URL, 'g',
username=GRAPH_DB_USER,
password=GRAPH_DB_PASSWORD)
)
edge = g.V(id).addE("rated").to(__.V(n_id)).next()