我正在使用
Nodejs
连接到neo4j
,以获取ServiceConsumer
节点的属性,但不确定如何实现。以下是我的代码,用于连接到neo4j。假设ServiceConsumer
有一些属性,例如city
,state
,name
,userId
,我需要检索ServiceConsumer的名称。我从前端获取userId
,并基于此查询neo4j数据库以获取节点信息。我该如何获取ServiceConsumer的名称?感谢您的帮助。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);
}
}
);