aseemk / node-neo4j-template

A template app for using Neo4j from Node.js.
http://node-neo4j-template.herokuapp.com/
216 stars 92 forks source link

queries return undefined #14

Closed golembuilder closed 10 years ago

golembuilder commented 10 years ago

Hi Aseemk,

I'm quite new to node, neo4j, express, etc. so, I'm probably making some simple error.

I've been using your template as a guide for my app. I can write to the neo4j and create new nodes using cypher queries, but everything comes back as undefined.

example code: User.getCourse = function(callback) { var query = ['MATCH (class:Course:CMPT)', 'RETURN class'].join('\n');

db.query(query, function(err, results) {
    if (err)
        return callback(err);
    var course = results.map(function (result) {
        return result['class'];
    });
    callback(err, course);
});

};

result['class'] comes back undefined. The nodes exist in neo4j and I can do the same query in their browser to get results. Any ideas?

aseemk commented 10 years ago

Yep: Cypher returns "results", so the returned results variable is always an array. You'll get what you want via results[0]['class']. This should fix your problem; feel free to reopen if it doesn't!