1

我是 Neo4J 的新手。到目前为止,我成功安装并启动了 Neo4J 服务器,并通过运行命令进行了检查neo4j status

通过使用 node-neo4j 驱动程序向数据库添加和更新节点。

在我的 nodejs 服务器中,我创建了一个新数据库:

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 行抛出以下异常(您可以在上面给出的代码片段中找到第 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)

然后,我尝试通过检查我的数据库来调试我的进程,并尝试在命令行上neo4j-shell键入dbinfo,我希望看到我的数据库和已经插入的 Darth Vader 节点。

但是,dbinfo什么都不返回!

如何使用 neo4j-shell 找到我的数据库和该数据库中的节点?

如何确保我成功插入了节点?如何读取已插入的节点?

你有什么主意吗?

先感谢您!

4

1 回答 1

2

说清楚点:有两个 node-neo4j 版本:

https://github.com/philippkueng/node-neo4j

https://github.com/thingdom/node-neo4j

您使用的是 philippkueng 版本:db.readNode仅适用于 nodeId。我认为您应该使用db.cypherQuery()cypher 语句来查询 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 已经提到的调试,请在以下位置使用 Neo4j 浏览器:

http://localhost:7474
于 2014-08-27T09:26:16.457 回答