-1

I have created a geohash neo4j database for NYC Taxi data. Now the next step is to visualize it within a map, for that i choosed Leaflet as a Javascript library. with static data i can plot geohash data in Leaflet:

geohash-leaflet

but now i want to query that data from the neo4j database and render it.

so is it possible to do that or only with a server side scripting language(node.js,php...) ?

Update

i found a simlair question here , the solution is to query the database with ajax however it dosen't work for me and i get "error" in the console:

var body = JSON.stringify({
            statements: [{
                statement: 'MATCH (n) RETURN count(n)'
            }]
        });
   $.ajax({
        url: "http://localhost:7474",
        type: "POST",
        data: body,
        contentType: "application/json"
    })
        .done(function(result){
            console.log(result);

        })
        .fail(function(error){
            console.log(error.statusText);
        });
Community
  • 1
  • 1
A.HADDAD
  • 1,809
  • 4
  • 26
  • 51

3 Answers3

1

It's possible to query Neo4j from client-side Javascript with Neo4j Driver for JavaScript.

I have used this in a couple of projects.

You can either download the driver and include in your HTML file like:

 <script src="lib/browser/neo4j-web.min.js"></script>

Or just use the CDN link like:

<script src="https://unpkg.com/neo4j-driver@X.Y.Z/lib/browser/neo4j-web.min.js"></script>
Rajendra Kadam
  • 4,004
  • 1
  • 10
  • 24
0

I find the solution:

first the url for the database is : "http://localhost:7474/db/data/transaction/commit" and not "http://localhost:7474".

then after changing that i got an unauthorized error in console , that means i need to add my user/password to my ajax call, this is done by a function called beforeSend like this:

beforeSend: function (xhr) {
                xhr.setRequestHeader ("Authorization", "Basic " + btoa("neo4j"+ ":" + "your_neo4j_password"));
            }}

so the final Ajax Solution is :

$.ajax({
            url: "http://localhost:7474/db/data/transaction/commit",
            type: "POST",
            data: body,
            contentType: "application/json",
            beforeSend: function (xhr) {
                xhr.setRequestHeader ("Authorization", "Basic " + btoa("neo4j"+ ":" + "password"));
            }}
            )
            .done(function(result){
                 console.log(result);
            }) 
            .fail(function(error){
                console.log(error.statusText);
            });
A.HADDAD
  • 1,809
  • 4
  • 26
  • 51
0

Rajendra Kadam's answer is correct.

First you need to install neo4j-driver by:

npm install neo4j-driver

in a directory probably one level higher than the web/ directory of your node.js server.

Then you need to put the neo4j-web.min.js into the web/ directory, where your client-side JavaScript can load.

Then you add the line in your HTML:

 <script src="js/neo4j-web.min.js"></script>

The file neo4j-web.min.js is located in node_modules/neo4j-driver/lib/browser/.

Then in your client-side JavaScript, put:

var driver = neo4j.driver(
    'neo4j://localhost',
    neo4j.auth.basic('neo4j', 'password') );

Then you have successfully opened the driver. (You may need to set your password correctly or you'll get an authentication error.)

Note that you DON'T need this line on your client-side JavaScript:

var neo4j = require('neo4j-driver');

because it is for server-side node.js.

Yan King Yin
  • 1,189
  • 1
  • 10
  • 25