cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to make Neo4j NodeJS code display the entire nodes data

sucheta
Graph Buddy

Hi,

I have integrated Neo4j in my NodeJS (backend) and Angular6 (front-end) application. My query runs and i get the data of nodes and connected node network in my Neo4j Browser. However, i want that entire data of nodes being displayed through a particular query on my console (i.e. in NodeJS -> back-end and angular ->front-end). This is not happening . I get only the first node data. Please help me retrieve the entire displayed nodal data in NodeJS .

NodeJS code

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


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



// //View Engine

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);
//router.post('/abc', tmsServer);

 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 LIMIT 250`) 
           .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);   
                //   console.log(" 2]record._fields =", record._fields);
                   res.send(record);           
               });
              
           })      
           .catch(function(err){
            console.log("inside catch = " + err);
        })
    
        session.close();   
}

output

 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 } ]
4 REPLIES 4

sucheta
Graph Buddy

Thanks. I resolved the issue.
The place and parameter i was passing in response was incorrect.

Correct code -

 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);   
                   console.log(" 2]record._fields = ", record._fields);
                //    res.send(record);           
               });
               res.send(result); 
              
           })      
           .catch(function(err){
            console.log("inside catch = " + err);
        })

What object is res in res.send(result) ?

res is the response and err is error .

For example , here i write the entire function below.


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].end.properties);   
                      
               });
               res.send(result); 
              
           })      
           .catch(function(err){
            console.log("inside catch = " + err);
        })
    
        session.close();   
}

I didn't understand that it was inside of a function from the original post. I'm just getting started with node etc. Anyhow, I got it to work by adding an app.get that routed to the function.