Neo4j NodeJS代码无法显示整个节点数据

时间:2018-11-16 11:32:16

标签: node.js neo4j

我已经将Neo4j集成到了NodeJS(后端)和Angular6(前端)应用程序中。我的查询运行,我在Neo4j浏览器中获取节点和连接的节点网络的数据。但是,我希望通过控制台上的特定查询来显示节点的全部数据(即在NodeJS->后端和angular->前端)。这没有发生。我只得到第一个节点数据。请帮助我在NodeJS中检索整个显示的节点数据。

NodeJS代码

neo4j-controller.js

// Require Neo4j
var neo4j = require('neo4j-driver').v1;

var path = require('path');
var logger = require('morgan');
var bodyParser = require('body-parser');
var express = require('express');

var router = express.Router();

var app = express();



 const driver = new neo4j.driver("bolt://localhost:11001", neo4j.auth.basic("neo4j", "ib1"));


 const cypher = 'MATCH (n) RETURN count(n) as count';




app.set('views', path.join(__dirname, 'views'));

 app.use(logger('dev'));
 app.use(bodyParser.json());
 app.use(bodyParser.urlencoded({ extended: false }));
 app.use(express.static(path.join(__dirname, 'public')));


var session = driver.session();
var request = require('request');

router.post('/', seekParameter);


 module.exports = router;


//working code below

// -------------------------------  Original Code  ----------------------------------------

function seekParameter(req, res) { 

    console.log("INSIDE NODE JS CONTROLLER OF seekParameter");

    console.log("BODY IS ", req.body);

        session

           .run(`MATCH p=()-[r:Parameter]->() RETURN p`)  
           .then(function (result){

               result.records.forEach(function(record){
                   console.log("record = ", record);
                   console.log("result = ", result)
                   console.log("1] record._fields[0].properties=",record._fields[0].properties);   

                   res.send(record);           
               });

           })      
           .catch(function(err){
            console.log("inside catch = " + err);
        })

        session.close();   
}

输出

 INSIDE NODE JS CONTROLLER OF seekParameter
BODY IS  undefined
record =  Record {
  keys: [ 'p' ],
  length: 1,
  _fields:
   [ Path { start: [Object], end: [Object], segments: [Array], length: 1 } ],
  _fieldLookup: { p: 0 } }
result =  { records:
   [ Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] } ],
  summary:
   ResultSummary {
     statement:
      { text: ' MATCH p=()-[r:Parameter]->() RETURN p ;',
        parameters: {} },
     statementType: 'r',
     counters: StatementStatistics { _stats: [Object] },
     updateStatistics: StatementStatistics { _stats: [Object] },
     plan: false,
     profile: false,
     notifications: [],
     server: ServerInfo { address: 'localhost:11001', version: 'Neo4j/3.4.7' },
     resultConsumedAfter: Integer { low: 9, high: 0 },
     resultAvailableAfter: Integer { low: 1, high: 0 } } }
1] record._fields[0].properties= { name: 'accidentTime' }
 2]record._fields[1] = [ Path {
    start: Node { identity: [Object], labels: [Array], properties: [Object] },
    end: Node { identity: [Object], labels: [Array], properties: [Object] },
    segments: [ [Object] ],
    length: 1 } ]
record =  Record {
  keys: [ 'p' ],
  length: 1,
  _fields:
   [ Path { start: [Object], end: [Object], segments: [Array], length: 1 } ],
  _fieldLookup: { p: 0 } }
result =  { records:
   [ Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] },
     Record {
       keys: [Array],
       length: 1,
       _fields: [Array],
       _fieldLookup: [Object] } ],
  summary:
   ResultSummary {
     statement:
      { text: ' MATCH p=()-[r:Parameter]->() RETURN p ;',
        parameters: {} },
     statementType: 'r',
     counters: StatementStatistics { _stats: [Object] },
     updateStatistics: StatementStatistics { _stats: [Object] },
     plan: false,
     profile: false,
     notifications: [],
     server: ServerInfo { address: 'localhost:11001', version: 'Neo4j/3.4.7' },
     resultConsumedAfter: Integer { low: 9, high: 0 },
     resultAvailableAfter: Integer { low: 1, high: 0 } } }
1] record._fields[0].properties= { name: 'productType' }
 2]record._fields[1] = [ Path {
    start: Node { identity: [Object], labels: [Array], properties: [Object] },
    end: Node { identity: [Object], labels: [Array], properties: [Object] },
    segments: [ [Object] ],
    length: 1 } ]

inside catch = Error: Can't set headers after they are sent.

1 个答案:

答案 0 :(得分:0)

谢谢。我解决了这个问题。 我在响应中传递的位置和参数不正确。

正确的代码-

session

           .run(` MATCH p=()-[r:Parameter]->() RETURN p ;`)  
           .then(function (result){

               result.records.forEach(function(record){
                   console.log("record = ", record);
                   console.log("result = ", result)
                   console.log("1] record._fields[0].properties = ",record._fields[0].end.properties);   
                //    res.send(record);           
               });
               res.send(result); 

           })      
           .catch(function(err){
            console.log("inside catch = " + err);
        })

        session.close();   
}