Response in the form of table/columns + data instead of records

Version Used: neo4j-enterprise-3.5.17
Using npm module neo4j-driver, we are able to establish a driver connection.
On using the session.run("Some read operations"), the result format is of records (i.e result.record).
Can we get the result in the format as we see in remote UI table OR Columns+data style.?( node-neo4j npm module does that, but doesn't support clustering.)

The expected result is exactly the one we get when we do http api request. Since we cannot do clustering + routing using http api, we are forced to use neo4j-driver which returns a different set of results.
So, how can we modify the stream results which Returns results in graph format? (https://neo4j.com/docs/developer-manual/3.4/http-api/#http-api-transactional)

Can anyone help me with this to resolve the issue.?

Hi Spulimi,

welcome to the Neo4j community.

I might not be able to help you solve your entire problem, but maybe I able to show you a way of how it could be solved. I myself am using Neo4j with Java but don't know too much about Javascript. So, what I am going to show you is how I convert the record into whatever I want it to be in Java. I hope that there are possibilities for you then to go and find the equivalent functionalities in javascript.

So let's take a simple cypher query:

MATCH (p:Person) return p.surname, p.name, p.homeTown

If I put the query into session.run, I obtain a result:

Result myResult = session.run("MATCH (p:Person) return p.surname, p.name, p.homeTown");

I then convert the result into a list of records (not sure how this is done in javascript):

List<Record> myRecords = myResult.list();

I can then create an array and iterate through all the records to fill my array with the received data:

int iter = 0;
String [][] myArray = new String[myRecords.size()][3];
for( Record record: myRecords){
   myArray[iter][0] = record.get("surname").asString();
   myArray[iter][1] = record.get("name").asString();
   myArray[iter][2] = record.get("homeTown").asString();
   iter++;
}

Now I have a "table" (array) with exactly the same data that is shown if I simply insert the cypher query into the Neo4j Browser.

I hope this helps you finding your way!
Regards,
Elena

Hello @spulimi1,

Depending on what you're trying to do using the JavaScript driver should be similar to using any of the other bolt drivers.

Are you trying to return this to an html table with the properties or aliases as the column headers?

Here's a very quick (ugly and brittle) example solution to pull the props out of any node into a table in vanilla-js.

I also recommend you check out the documentation for the js driver, along with the GitHub ReadMe.

<html>
  <header>
    <!-- https://github.com/neo4j/neo4j-javascript-driver/blob/4.0/README.md -->
    <script src="https://unpkg.com/neo4j-driver"></script>
  </header>
  <table>
    <thead>
      <tr id="header"></tr>
    </thead>
    <tbody id="body"></tbody>
  </table>
  <script type="text/javascript">
    let header = document.getElementById("header");
    let body = document.getElementById("body");

    example();

    async function example() {
      const driver = neo4j.driver(
        "bolt://localhost:7687",
        neo4j.auth.basic("neo4j", "graph")
      );
      const session = driver.session();
      try {
        const result = await session.run("MATCH (n) RETURN n");

        // Assumes all nodes returned have the same properties as the first one returned.
        Object.keys(result.records[0].get(0).properties).forEach((key) => {
          let colHead = document.createElement("th");
          let headerText = document.createTextNode(key);
          colHead.appendChild(headerText);
          header.appendChild(colHead);
        });

        // There are nicer ways to do this. This is just a hacked together example.
        result.records.forEach((record) => {
          let row = document.createElement("tr");
          Object.values(record.get(0).properties).forEach((val) => {
            let cell = document.createElement("td");
            let text = document.createTextNode(val);
            cell.appendChild(text);
            row.appendChild(cell);
          });
          body.appendChild(row);
        });
      } finally {
        await session.close();
      }
      await driver.close();
    }
  </script>
</html>