使用node-neo4j读取节点时出现问题&使用neo4j-shelldebugging技巧
我是Neo4J的新手。 到目前为止,我成功安装并启动了Neo4J服务器,并通过运行命令neo4j status
检查它。
通过使用node-neo4j驱动程序向数据库添加和更新节点。
在我的nodejs服务器中,我创build了一个新的数据库:
db = new neo4j("http://127.0.0.1:7474");
接下来,我插入一个新节点:
db.insertNode( {"name": "Darth Vader","sex": "male"}, (err, node) -> if err then throw err console.log "Insert node" console.log node )
插入新节点时,我不会遇到任何错误。 但是,当我尝试读取此节点
db.readNode( {"name": "Darth Vader"}, (err, node) -> if err then throw err; # 48th line of server.js console.log "Read node" console.log node )
ReadNode函数在第48行抛出以下exception(您可以在上面给出的代码片段中find第48行)。
server.js:48 throw err; ^ Error: HTTP Error 500 occurred while reading a node. at node_modules/node-neo4j/main.js:151:15 at Request.callback (node_modules/node-neo4j/node_modules/superagent/lib/node/index.js:656:3) at Request.<anonymous> (node_modules/node-neo4j/node_modules/superagent/lib/node/index.js:131:10) at Request.emit (events.js:95:17) at IncomingMessage.<anonymous> (node_modules/node-neo4j/node_modules/superagent/lib/node/index.js:802:12) at IncomingMessage.emit (events.js:117:20) at _stream_readable.js:929:16 at process._tickCallback (node.js:419:13)
然后,我尝试通过检查我的数据库来debugging我的进程,并尝试neo4j-shell
并在命令行键入dbinfo
,我期望看到我的数据库和已经插入的Darth Vader节点。
但是, dbinfo
什么也没有返回!
我怎样才能find我的数据库,并在这个数据库中的节点neo4j壳?
我怎样才能确保我成功插入节点? 我如何读取已经插入的节点?
你有什么主意吗?
先谢谢你!
清楚一点:有两个node-neo4j版本:
https://github.com/philippkueng/node-neo4j
https://github.com/thingdom/node-neo4j
您正在使用philippkueng版本: db.readNode
将只使用nodeId。 我想你应该使用db.cypherQuery()
和db.cypherQuery()
语句来查询neo4j数据库。
例如:
db.cypherQuery('MATCH (n {name: "Darth Vader"}) RETURN n', function(err, result){ if(err) throw err; console.log(result.data); // delivers an array of query results console.log(result.columns); // delivers an array of names of objects getting returned });
是否要使用不带Cypher的标签和索引来查找可以使用的节点:
// add Darth Vader with the label Person db.insertNode( {name: 'Darth Vader',sex: 'male'}, 'Person', function(err, node) {}) db.readNodesWithLabelsAndProperties('Person', {name: 'Darth Vader'}, function (err, result) {})
作为@codewithcheese的debugging,已经提到在以下位置使用Neo4j浏览器:
http://localhost:7474