0
const getIds = () => {
    session
        .run('MATCH (m :Movie) RETURN m.imdbId LIMIT 10')
        .then(result => {
            const ids = [];
            result.records.forEach(record => ids.push(record._fields[0]));
            return ids;
        })
        .catch(err => console.log(err));
}

const imdbIds = getIds();
console.log(imdbIds);

I want to get a list of movie IDs from my neo4j database but when I log my array to the console it says its undefined. P. S. I'm new to javascript.

Teymour
  • 1,832
  • 1
  • 13
  • 34
Aniruth N
  • 104
  • 1
  • 7
  • 1
    You need to return the Promise and then consume it with `.then` – CertainPerformance Jan 09 '20 at 08:58
  • ^^ and remove the `catch` from `getIds` (since with what's there, whatever calls `getIds` will receive a fulfillment with `undefined` if an error occurs). Handle errors at the caller level (or have the caller return the promise chain to something *else* that will handle errors). – T.J. Crowder Jan 09 '20 at 09:02

0 Answers0