我发现neo4j3.0 bolt neo4j-driver语法非常具有挑战性。我的会话代码不会执行,显然它会被跳过。我使用开发人员手册中的示例创建了一个小测试代码,并且惊喜地发现了同样的事情。我使用node-inspector查看代码,确定它只是跳过了“session”块。显然我做错了什么...有人能告诉我它是什么?? ...代码如下:.....代码只打印第一个console.log然后退出。
var neo4j = require('neo4j-driver').v1;
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "allin4k"));
var session = driver.session();
console.log("start session");
session
.run( "CREATE (a:Person {name:'Arthur', title:'King'})" )
.then( function()
{
console.log("return from second session")
return session.run( "MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title" )
})
.then( function( result ) {
console.log( result.records[0].get("title") + " " + result.records[0].get("name") );
session.close();
driver.close();
})
答案 0 :(得分:2)
不确定您的期望。
使用会话结果,您在同一会话中运行第二个语句,同时关闭它?
你的第二个then
应该是第二个电话:
var neo4j = require('neo4j-driver').v1;
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "allin4k"));
var session = driver.session();
console.log("start session");
session
.run( "CREATE (a:Person {name:'Arthur', title:'King'})" )
.then( function()
{
console.log("return from second session")
session.run( "MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title" ).then( function( result ) {
console.log( result.records[0].get("title") + " " + result.records[0].get("name") );
session.close();
driver.close();
})
})