cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Expect disruption to service on Thursday, Feb. 9!

Error on receiving Json Data

Im trying to do a simple application with neo4j and nodejs, but I've just get stuck in this strange response. I'm inserting things on neo4j and it works, but when I try to use cypher to catch other node attributes i find this mistake:

 Result {
      _stack: '\n    at captureStacktrace (/home/jake/node_modules/neo4j-driver/lib/v1/result.js:199:15)\n    at new Result (/home/jake/node_modules/neo4j-driver/lib/v1/result.js:65:19)\n    at Session._run (/home/jake/node_modules/neo4j-driver/lib/v1/session.js:152:14)\n    at Session.run (/home/jake/node_modules/neo4j-driver/lib/v1/session.js:130:19)\n    at /home/jake/Área de Trabalho/simples/index.js:16:31\n    at Layer.handle [as handle_request] (/home/jake/node_modules/express/lib/router/layer.js:95:5)\n    at next (/home/jake/node_modules/express/lib/router/route.js:137:13)\n    at Route.dispatch (/home/jake/node_modules/express/lib/router/route.js:112:3)\n    at Layer.handle [as handle_request] (/home/jake/node_modules/express/lib/router/layer.js:95:5)\n    at /home/jake/node_modules/express/lib/router/index.js:281:22',
  _streamObserver: 
   SessionStreamObserver {
     _fieldKeys: null,
     _fieldLookup: null,
     _queuedRecords: [],
     _tail: null,
     _error: null,
     _hasFailed: false,
     _observer: null,
     _conn: null,
     _meta: {},
     _session: 
      Session {
        _mode: 'WRITE',
        _readConnectionHolder: [Object],
        _writeConnectionHolder: [Object],
        _open: true,
        _hasTx: false,
        _lastBookmark: [Object],
        _transactionExecutor: [Object] } },
  _p: null,
  _statement: 'MATCH (p:Person) WHERE p.name =\'$name\' return p.age',
  _parameters: { name: 'Jake' },
  _metaSupplier: [Function],
  _connectionHolder: 
   ConnectionHolder {
     _mode: 'WRITE',
     _connectionProvider: 
      DirectConnectionProvider {
        _address: [Object],
        _connectionPool: [Object],
        _driverOnErrorCallback: [Function: bound _driverOnErrorCallback] },
     _referenceCount: 1,
     _connectionPromise: Promise { <pending> } } }'

To make it clear: i just want to find a node by its name and then show its age. I was expecting a Json data.

My code:

`const express = require ("express");
const app = express();
const bodyParser = require('body-parser');

app.use(bodyParser());

//Conec
const neo4j = require('neo4j-driver').v1;
const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic('neo4j', '123'));
const session = driver.session();

// Data Manipulation

app.post('/', function (req, res){
var find = req.body.pesquisa;
  const result_dois = session.run("MATCH (p:Person) WHERE p.name ='$name' return p.age", {name:find});

  console.log(result_dois);

res.end();

});

If someone could help...

1 REPLY 1

webtic
Graph Fellow

Never used the javascript driver myself but I am giving it a shot

Perhaps the session.run should be awaited for?

Its what I notice looking at the example of the driver:

const neo4j = require('neo4j-driver')

const driver = neo4j.driver(uri, neo4j.auth.basic(user, password))
const session = driver.session()
const personName = 'Alice'

try {
  const result = await session.run(
    'CREATE (a:Person {name: $name}) RETURN a',
    { name: personName }
  )

  const singleRecord = result.records[0]
  const node = singleRecord.get(0)

  console.log(node.properties.name)
} finally {
  await session.close()
}

// on application exit:
await driver.close()