首页 > 解决方案 > 找不到方法:带有 neo4j 插件和 gremlin 服务器的 DefaultGraphTraversal.to

问题描述

我正在使用 nodejs 的 gremlin 插件,使用嵌入式 neo4j 图与 gremlin 服务器通信。我能够查询和创建顶点,但由于“无法定位方法:DefaultGraphTraversal.to”错误而无法创建任何边。有任何想法吗??

我可以使用连接到与 nodejs 程序相同的 gremlin 服务器的 gremlin 控制台创建顶点和边。

Gremlin 控制台和服务器 3.4.1 Gremlin NodeJS npm 3.4.1 Tinkerpop Neo4J-gremlin 插件:3.4.1

const gremlin = require('gremlin');
const traversal = gremlin.process.AnonymousTraversalSource.traversal;
const Graph = gremlin.structure.Graph;
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;

const g = traversal().withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin'));

async function run(){

    const phil = await g.V().has('name', 'phil').next();
    console.log("Have Phil: " +JSON.stringify(phil ));

    g.V().has('name', 'stephen').next()
    .then(stephen => {
        console.log("Have Steve: " +JSON.stringify(stephen));
        const e1 = g.V(phil).addE('friends').to(stephen).next();
        console.log(e1);
    })
    .catch(err => console.log(err));

}

run();

下面是输出。如您所见,我能够很好地获取顶点,但在边缘创建期间收到此错误。

Have Phil: {"value":{"id":18,"label":"person"},"done":false}
gremlin.js:13
Have Steve: {"value":{"id":7,"label":"person"},"done":false}
gremlin.js:17
Promise { pending }
gremlin.js:19
(node:48830) UnhandledPromiseRejectionWarning: Error: Server error: Could not locate method: DefaultGraphTraversal.to([{value={id=7, label=person}, done=false}]) (599)
    at Connection._handleMessage (/Users/byronbailey/OneDrive - Cargill Inc/VSC/GraphTest/node_modules/gremlin/lib/driver/connection.js:265:9)
    at WebSocket._ws.on (/Users/byronbailey/OneDrive - Cargill Inc/VSC/GraphTest/node_modules/gremlin/lib/driver/connection.js:128:43)
    at WebSocket.emit (events.js:189:13)
    at Receiver._receiver.onmessage (/Users/byronbailey/OneDrive - Cargill Inc/VSC/GraphTest/node_modules/ws/lib/WebSocket.js:141:47)
    at Receiver.dataMessage (/Users/byronbailey/OneDrive - Cargill Inc/VSC/GraphTest/node_modules/ws/lib/Receiver.js:380:14)
    at Receiver.getData (/Users/byronbailey/OneDrive - Cargill Inc/VSC/GraphTest/node_modules/ws/lib/Receiver.js:330:12)
    at Receiver.startLoop (/Users/byronbailey/OneDrive - Cargill Inc/VSC/GraphTest/node_modules/ws/lib/Receiver.js:165:16)
    at Receiver.add (/Users/byronbailey/OneDrive - Cargill Inc/VSC/GraphTest/node_modules/ws/lib/Receiver.js:139:10)
    at Socket._ultron.on (/Users/byronbailey/OneDrive - Cargill Inc/VSC/GraphTest/node_modules/ws/lib/WebSocket.js:138:22)
    at Socket.emit (events.js:189:13)
warning.js:18
(node:48830) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
warning.js:18
(node:48830) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

标签: neo4jgremlin-server

解决方案


问题是参数的数据类型。我之前尝试过这个解决方案的不同版本,但显然仍然没有达到目标。addE 行代码应如下所示。 这个 Azure 示例帮助连接了这些点。

gV(phil.value.id).addE('knows').to(gV(stephen.value.id)).next()


推荐阅读