John Sorensen
John Sorensen

Reputation: 960

Interpreting Neo4j Returned Records

The return scheme for Cypher queries has generally been complex, but I am especially confused on how to access the integer result of a returned count. Is the wrong number showing up or I am I accessing the result in the wrong way?

Query:

MATCH (self:USER {userID: $userID})-[r:FRIEND]-(other:USER) RETURN count(other)

Logged Record:

Record {
    keys: [ 'count(other)' ],
    length: 1,
    _fields: [ [Integer] ],
    _fieldLookup: { 'count(other)': 0 }
}

I called _fieldLookup and logged the result:

{ 'count(other)': 0 }

I know for a fact that the actual count is 2, as I can visually verify my database through the neo4j browser. Is the query simply wrong or I am accessing it in the wrong way?

I would also appreciate any docs on the return schema for cypher queries. I haven't found anything that discusses that yet.

EDIT: Screenshot of Graph

graph

I was testing my query on "userID_2", who does in fact have two friends. I also tried this query on some other users in the database, and while some do in fact have zero, the query always returned:

{ 'count(other)': 0 }

EDIT 2:

I tried logging this

console.log(result.records[0].get(0));

But got this strange result:

Integer { low: 2, high: 0 }

2 is the correct count for my query, though I am confused why high exists.

Upvotes: 0

Views: 339

Answers (1)

Dan Starns
Dan Starns

Reputation: 3825

Try this:

const count = executeResult.records[0].get(0);

It gets the value from a record by the index or by field key reference

Upvotes: 1

Related Questions