slotdp02
slotdp02

Reputation: 438

Return related user id in cypher query

I'm looking to return the users' node id from the query. Ideally that id would be paired as a property with each of the returned users but could also come as an array of corresponding id's of the returned users.

Here's the current query

var query = [
    'MATCH (f:FundRaiser)<-[t:TRANSACTION]-(u:User)',
    'WHERE ID(f) ='+ fundraiserId,
    'RETURN COLLECT(DISTINCT u)as users,COLLECT(DISTINCT t) as transactions'
].join('\n');

Upvotes: 1

Views: 189

Answers (1)

cybersam
cybersam

Reputation: 67019

This query string should produce a result in which users would be a collection of distinct objects, each containing a User node and its native ID.

var query = [
    'MATCH (f:FundRaiser)<-[t:TRANSACTION]-(u:User)',
    'WHERE ID(f) ='+ fundraiserId,
    'RETURN COLLECT(DISTINCT {u: u, id: ID(u)}) as users, COLLECT(DISTINCT t) as transactions'
].join('\n');

NOTE: You should pass the fundraiserId value as a parameter, which would be more secure and performant.

Upvotes: 1

Related Questions