1

I have a AQL query and the query works fine. Instead of printing out the result in the console. How can I get the value(result) of this query into a function ?

1.I hope this question is not too vague

example query

db.query(aqlQuery `
                 LET startVertex = (FOR doc IN spec
                 FILTER doc.serial_no == '"123456abcde"'
                 LIMIT 2
                 RETURN doc
                 )[0]

                FOR v IN 1 ANY startVertex belongs_to
                RETURN v.ip`, {
  bindVar1: 'value',
  bindVar2: 'value',
}).then(function(res) {
  console.log("doc" + res._result);
})

console output :

  • doc,192.168.72.237
0

1 Answer 1

1

You could wrap this code in an async function that returns query results, and use it with await keyword:

async function dbQuery(/* your params */) {
    const res = await db.query(/* your query */);
    return res._result;
}

// usage inside another async function
const result = await dbQuery(/* params */);
Sign up to request clarification or add additional context in comments.

5 Comments

if you dont mind..,can you tell me what you mean by params in this context
it should me something like this ., dBQuery(res, req) ? Is that right ?
it throws an Unexpected Identifier error: await dbQuery();
params is whatever parameters you prefer to pass to this function, it is a matter of design. It could be a query string, for example. Regarding the error, you probably didn't use the call inside another async function. Please follow the links in my answer to learn more.
yes I get it..,I have used nothing for instance..,then I even declared dbQuery(); at the end of the file..still there is an Unexpected Identifier error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.