arangodb / arangojs

The official ArangoDB JavaScript driver.
https://arangodb.github.io/arangojs
Apache License 2.0
600 stars 106 forks source link

Pokemon example doesn't work (pokemons not initialized) #715

Closed enjoysmath closed 3 years ago

enjoysmath commented 3 years ago
var arangojs = require('arangojs');

const aql = arangojs.aql;
const await = arangojs.await;

// Const variables for connecting to ArangoDB database
const host = '127.0.0.1'
const port = '8529'
const username = 'root'
const password = 'lunamoona'
const databasename = 'testDB'

 // Connection to ArangoDB
db = new arangojs.Database({
    url: `http://${host}:${port}`,
    databaseName: databasename,
    precaptureStackTraces: true,
});

db.useBasicAuth(username, password);

const pokemons = db.collection("testCollection");

async function main() {
  try {
    const pokemons = await db.query(aql`
      FOR pokemon IN ${pokemons}
      FILTER pokemon.type == "fire"
      RETURN pokemon
    `);
    console.log("My pokemons, let me show you them:");
    for await (const pokemon of pokemons) {
      console.log(pokemon.name);
    }
  } catch (err) {
    console.error(err.message);
  }
}

main();

Outputs error: Cannot access 'pokemons' before initialization

pluma commented 3 years ago

Oops, thanks for catching this. There are two variables with the same name. I'll fix the documentation.