How to get Neo4j node attributes

I connect to neo4j in Nodejs to get the ServiceConsumer node attribute. But not sure how to do it. here is my code that connects to neo4j. Suppose ServiceConsumer has attributes like city , state , name , userId , and I need to get the name ServiceConsumer. I get userId from the front end and based on this userId the neo4j database query to get node information. How to get the name ServiceConsumer? Any help would be appreciated.

 var user = this.userId; var request = require("request"); var host = 'localhost'; port = 7474; var httpurlforconnection ='http://' + host + ':' + port + '/db/data/transaction/commit'; /*Let's define a function which fires the cypher query.*/ function runCypherQuery(query, user, callback) { request.post({ uri: httpUrlForTransaction, json: {statements: [{statement: query, parameters: user}]} }, function (err, res, body) { callback(err, body); }) } // Let's fire some queries below runCypherQuery( 'MATCH (n:ServiceConsumer {userId : {} }) RETURN n', { userId: 'user', }, function (err, resp) { if (err) { console.log(err); } else { console.log(resp); } } ); 
+4
source share
2 answers

Take a look at How to return all node properties with their name and their value using Cypher

You can do the same using nodejs, a simple POST can return the entire node to you and then just pass it to the object using JSON.

By the way, your code is working fine, you can just take the "resp" object, which should contain the JSON result.

+1
source

One obvious thing that I see is that you are not specifying the userId parameter. You, Cypher, should look something like this:

 MATCH (n:ServiceConsumer {userId: {user_id}}) RETURN n 

Does it help?

0
source

All Articles