0

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?

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

It seems I just used the wrong method there. Correct would've been:

const user = await db.executeTransaction(
    {
      read: ['beusers'],
    },
    `
      function() {
        // This code will be executed inside ArangoDB!
        const { query } = require("@arangodb");
        return query\`
            FOR user IN ${col.name}
            FILTER user.password == "${stringHash(
              passedUser.password,
            )}" && user.email == "${stringHash(passedUser.email)}"
            RETURN user
          \`.toArray()[0];
      }
    `,
  )

Comments

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.