Skip to content

Instantly share code, notes, and snippets.

@thejhh
Created November 15, 2012 07:44
Show Gist options
  • Select an option

  • Save thejhh/4077250 to your computer and use it in GitHub Desktop.

Select an option

Save thejhh/4077250 to your computer and use it in GitHub Desktop.
Usage of Neo4j query with promise support to list all nodes a user has read access
/** Get available objects for current user */
server.get('/', function(req, res, next) {
var username = req.authorization.basic.username;
db_query([
'START root=node(0)',
'MATCH root-[:USERS_REF]->uroot-[:USER]->user-[:ACCEPT_READ]->n',
'WHERE user.name = {username}',
'RETURN n'
], {'username': username}).then(function(results) {
var nodes = [];
if( results && results.length ) {
foreach(results).each(function(node) {
var n = node.data;
n._id = node.id;
nodes.push(n);
});
}
return next(nodes);
}, function(err) {
console.log('Neo4j query failed: ' + err);
if(err.stack) console.log('stack: ' + err.stack);
next(new restify.InternalError("Database query failed"));
});
});
@thejhh

thejhh commented Nov 15, 2012

Copy link
Copy Markdown
Author

Error message:

Neo4j query failed: Error: key not found: user

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment