cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Getting null/undefined as values from relationship keys

Hello everyone,
I am quite new to the Neo4j platform (having an experience of only 2.5 months) and in the middle of creating an application in Node.JS with neo4j-driver to work on a graphdb in neo4j-aura.
One of my queries involves taking all the relationships matched against a node query, extracting all the elements in every relationship result into separate arrays (named after that element).

    const neoDriver = neo4j.driver(neo4jURI, neo4j.auth.basic(neoUser, neoPass), { disableLosslessIntegers: true });
    const neoSession = neoDriver.session();
    let readQuery, readResult, result = []; //read result and pass to a result array all data
    let ids = [], start = [], end = [], type = [], prop = [];
    let collection = 'toys';
    let id1 = 123456; //pointer id
    //read query and parse result
    readQuery = `MATCH (n: ${collection}) - [r] -> (n2) WHERE any(key in keys(n) WHERE n[key] = ToInteger($id1)) RETURN [r]`
    readResult = await neoSession.writeTransaction(tx =>
        tx.run(readQuery, { id1 })
    )
    readResult.records.forEach(record => {
        let len = record.length;
        let keys = record.keys;
        for (let i = 0; i < len; i++) {result.push(record.get(keys[i]));}
        for (let i = 0; i < len; i++){
            ids.push(result[i].identity);
            start.push((record.get(keys[i]).start));
            end.push((record.get(keys[i]).end));
            type.push((record.get(keys[i]).type));
            prop.push((record.get(keys[i]).properties));
        } 
    })

Now, if I were to print the 'result' array out into my terminal i get an output like this:

[
  [
    Relationship {
      identity: 919,
      start: 49,
      end: 629,
      type: 'IS_PLAYED_WITH',
      properties: [Object]
    }
  ],
  [
    Relationship {
      identity: 103,
      start: 49,
      end: 690,
      type: 'HAS_A',
      properties: {}
    }
  ],
  [
    Relationship {
      identity: 156,
      start: 49,
      end: 80,
      type: 'HAS_A',
      properties: {}
    }
  ]
]

A total of 3 relationships are returned according to that cypher query.
IS_PLAYED_WITH relationship has properties and thus I surmise it returns me an [Object] in my terminal whereas the other relationship don't have properties (or are empty).

If now, I try and get the other separate arrays to print their data in my terminal out. All i get is:

[ undefined, undefined, undefined ]

As seen, in the result array, there are clearly values present in the result array. However, any effort in extracting them returns me null/undefined type.

I hope you can understand my problem faced here? If not, please do ask me for clarifications.
I thank the community in advance for taking the time to help an initiate developer.

Regards,
Cael

0 REPLIES 0