1

I'm new to Neo4J. So far, I successfully installed and started the Neo4J server and I checked it by running the command neo4j status.

By using node-neo4j driver to add & update nodes to the database.

In my nodejs server, I create a new database:

db = new neo4j("http://127.0.0.1:7474");

Next, I insert a new node:

db.insertNode( {"name": "Darth Vader","sex": "male"}, (err, node) ->
  if err then throw err
  console.log "Insert node"
  console.log node
)

I face no error when inserting a new node. However, when I try to read this 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 function throws the following exception at 48th line( you can find the 48th line at the code snippet given above).

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)

Then, I tried to debug my process by checking my database and tried neo4j-shell and typed dbinfo on the command line, I expected to see my database and the Darth Vader node that already inserted.

However, dbinfo returns nothing at all!

How can I find my databases, and nodes in this database with neo4j-shell?

How can I make sure that I successfully inserted the node? How can I read the node that I already inserted?

Do you have any idea?

Thank you in advance!

ankakusu
  • 1,738
  • 8
  • 26
  • 37
  • 2
    Have you tried viewing the neo4j browser at http://localhost:7474/browser – Codewithcheese Aug 26 '14 at 21:40
  • That's cool! Yes, I can see my node over there. Now, what is the problem with `db.readNode` ? Do I give wrong input to search a node? – ankakusu Aug 26 '14 at 21:54
  • Is this the library you are using? http://coffeedoc.info/github/thingdom/node-neo4j/master/ – Codewithcheese Aug 26 '14 at 22:22
  • That is wierd. There are two libraries with the same name. I'm using [this node-neo4j library](https://github.com/philippkueng/node-neo4j). I'm going to check this library as well. Cause it has more stars :) Thanks! – ankakusu Aug 27 '14 at 07:09

1 Answers1

2

To make things clear: There are two node-neo4j version out there:

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

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

You are using the philippkueng version: db.readNode will work with nodeId's only. I think you should use db.cypherQuery() with a cypher statement instead for querying the neo4j database.

For example:

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
});

Is you want to use labels and indexes without Cypher to lookup the node you could use this:

// 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) {})

For debugging as @codewithcheese already mentions use the Neo4j browser at:

http://localhost:7474
  • I see. So, can I state that, db.cypherQuery() is the only way to make a query like I want the nodes with `"name": "Darth Vader"`? – ankakusu Aug 27 '14 at 13:22
  • 1
    Cypher (http://docs.neo4j.org/chunked/stable/cypher-query-lang.html) is the query language of Neo4j. Compare Cypher with SQL. Using Cypher is a very intuitive way to interact with Neo4j. Is it the only way? No the node-neo4j driver you are using has support for Labels and indexes on labels so you can take a look at: `readNodesWithLabelsAndProperties` and read the Labels and index sections from the neo4j documentation mentioned above. – Ron van Weverwijk Aug 27 '14 at 13:32
  • @ankakusu What is the thing that is not user friendly in your opinion? The Cypher language or the db.cypherQuery api from the node-neo4j plugin? – Ron van Weverwijk Aug 27 '14 at 13:45
  • First of all, thank you very much for your help and answers! They were quite helpful :) The Cypher language is good. No problem with that. I found db.cypherQuery api not user friendly. I'm checking `readNodesWithLabelsAndProperties` function, now. I think it fits my expectations. – ankakusu Aug 27 '14 at 14:04