arangodbarangojs

How to get the data of a query in arangojs


Hello I'm using arangojs, created a database, added data to the collection beusers.

Now I want to read the added data. In ArangoDB I can do so using the query

FOR user IN beusers
FILTER user.password == '3670747394' && user.email == '3817128089'
RETURN user

Doing

const user = await usedDB.parse(aql`
        FOR user IN ${usersCol.name}
        FILTER user.password == ${hashedPassword} && user.email == ${hashedEmail}
        RETURN user
`)
console.log(user)

in arangojs I get

{
  error: false,
  code: 200,
  parsed: true,
  collections: [],
  bindVars: [ 'value2', 'value0', 'value1' ],
  ast: [ { type: 'root', subNodes: [Array] } ]
}

The example in the readme got me only so far.

What am I missing? How can I read the data?


Solution

  • You want to use Database.query() to get a cursor (ArrayCursor) and then you want to return the value in the cursor's result list (for example using ArrayCursor.all()).

    So the code would look like this:

    const cursor = await usedDB.query(aql`
      FOR user IN ${usersCol.name}
        FILTER user.password == ${hashedPassword} && user.email == ${hashedEmail}
        RETURN user
    `);
    console.log(await cursor.all()); // returns array of users