我正在使用用于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.
答案 0 :(得分:0)
问题是参数的数据类型。我之前曾尝试过该解决方案的不同版本,但显然仍然错过了这个机会。代码的addE行应如下所示。 This Azure sample帮助连接了各个点。
g.V(phil.value.id).addE('knows')。to(g.V(stephen.value.id))。next()