问题描述:

I am trying to write a node.js app that works with neo4j, using the node-neo4j module. I am trying to submit a query from nodejs and found it wasn't working, so I tried submitting it from the neo4j browser console, in order to more easily root cause my typo, and found that it worked properly there. Any ideas as to what is going on?

The query:

Match (a:Paper { uid:26327110, citation:"Seitz A. \"Moving beyond a binary view of specificity in perceptual learning.\" Journal of vision. 15 12 (2015 Sep 1): 1422.", date:"2015 Sep 1"}) return a

网友答案:

You should probably be using parameters anyway and they might help with any encoding issues. That would look like this:

var query_string = "MATCH (a:Paper {attributes}) RETURN a"

var attributes = {uid: 26327110, citation: "Seitz A. \"Moving beyond a binary view of specificity in perceptual learning.\" Journal of vision. 15 12 (2015 Sep 1): 1422.", date: "2015 Sep 1"};

db.cypherQuery(query_string, {attributes: attributes});

Of course you can use individual parameters for individual values if you like. Not only do parameters help you not worry about encoding, but the allow Neo4j to cache the query. Also, if you are passing in values from the user parameters also help you to prevent injection attacks.

网友答案:

In this situation, it turns out I was just an idiot - the error occurred because I created a new database with a new password and forgot to adjust my node server's authentication. If you ever have a similar issue and see the following error in your node console: [Error: HTTP Error 401 when running the cypher query against neo4j. undefined: undefined] then you too, have a case of the idiot. As Kunal suggested in the comments to the original question, check your authentication.

相关阅读:
Top