I want to execute a simple query in my database arangodb with nodejs for a login page.
var arango = require('arangojs');
/*---*/
Database = arango.Database;
db = new Database('http://127.0.0.1:8529');
db.useDatabase('MyDB');
db.useBasicAuth('root', 'root');
/*---*/
//Post Methods
var username;
var passworddb;
//Login method
app.post('/', function (request, response) {
username = request.body.user.name;
db.query('FOR u IN User FILTER u.firstname == "'+username+'" RETURN u.password').then(
cursor => cursor.all()
).then(
key => console.log('key:', key),
//key => passworddb = key,
err => console.error('Failed to execute query')
);
console.log(passworddb)
});
It's working, but i can't save in my var passworddb the result of the key... I don't undertand... the request is asynchronous in arangodb
Console.write(passworddb) return "undefined" and after console.log('key:', key) return correctly the key... Twice.
My question is : how can i get only the password in arangodb (What is the query for once request) and how to store the value in my var ?
Thank you for your answers.