thingdom / node-neo4j

[RETIRED] Neo4j graph database driver (REST API client) for Node.js
Apache License 2.0
925 stars 135 forks source link

why does the REST api return URL value? #176

Closed pangguoming closed 8 years ago

pangguoming commented 8 years ago

i get results like:

{
    "path":{
        "directions":[
            "->",
            "->",
            "->",
            "->"
        ],
        "start":"http://localhost:7474/db/data/node/905",
        "nodes":[
            "http://localhost:7474/db/data/node/905",
            "http://localhost:7474/db/data/node/767",
            "http://localhost:7474/db/data/node/770",
            "http://localhost:7474/db/data/node/814",
            "http://localhost:7474/db/data/node/819"
        ],
        "length":4,
        "relationships":[
            "http://localhost:7474/db/data/relationship/4478",
            "http://localhost:7474/db/data/relationship/3902",
            "http://localhost:7474/db/data/relationship/4465",
            "http://localhost:7474/db/data/relationship/4466"
        ],
        "end":"http://localhost:7474/db/data/node/819"
    }
}

Why are all value URL ?

aseemk commented 8 years ago

What version of node-neo4j are you running? And can you paste your code?

pangguoming commented 8 years ago

i user version "neo4j": "2.0.0-RC2"

the following is my code: may be it is because of :shortestPath function

var neo4j = require('neo4j');
var db = new neo4j.GraphDatabase('http://neo4j:pgmopen@localhost:7474');

var cypher_params = {
    start: 'Universidades' ,
    end: 'Portal de la 80'
};

var query = [
    'MATCH path=shortestPath(',
    '(st1:STATION {name:{start}})-[*]-(st2:STATION {name:{end}})',
    ')',
    'RETURN path'
].join('\n');

db.cypher({
    query: query,
    params: cypher_params
}, function (err, results) {
    if (err) throw err;
    var result = results[0];
    if (!result) {
        console.log('No user found.');
    } else {
        console.log(JSON.stringify(result));
    }
});
aseemk commented 8 years ago

Okay, thanks.

Yes, returning paths directly isn't recommended with db.cypher, because Neo4j's REST API indeed only returns URLs. Instead, consider returning NODES(path) or similar.

Full reference of functions: http://neo4j.com/docs/stable/query-functions-collection.html

Does that help?

pangguoming commented 8 years ago

RETURN NODES(path),relationships(path)

i think that is the only way, thanks a lot sir.