0
votes

I'm new to cypher, neo4j and graph databases in general. The data model I was given to work with is a tad confusing, but it looks like the nodes are just GUID placeholders with all the real "data" as properties on relationships to the nodes (which relates each node back to node zero).

Each node (which basically only has a guid) has a dozen relations with key/value pairs that are the actual data I need. (I'm guessing this was done for versioning?.. )

I need to be able to make a single cypher call to get properties off two (or more) relationships connected to the same node -- here is two calls that I'd like to make into one call;

start n = Node(*)
match n-[ar]->m
where has(ar.value) and has(ar.proptype) and ar.proptype = 'ccid' 
return ar.value

and

start n = Node(*)
match n-[br]->m
where has(br.value) and has(br.proptype) and br.proptype = 'description'
return br.value

How do I go about doing this in a single cypher call?

EDIT - for clarification;

I want to get the results as a list of rows with a column for each value requested.

Something returned like;

n.id as Node, ar.value as CCID, br.value as Description

2

2 Answers

3
votes

Correct me if I'm wrong, but I believe you can just do this:

start n = Node(*)
match n-[r]->m
where has(r.value) and has(r.proptype) and (r.proptype = 'ccid' or r.proptype = 'description') 
return r.value

See here for more documentation on Cypher operations.

Based on your edits I'm guessing that you're actually looking to find cases where a node has both a ccid and a description? The question is vague, but I think this is what you're looking for.

start n = Node(*)
match n-[ar]->m, n-[br]->m
where (has(ar.value) and has(ar.proptype) and ar.proptype = 'ccid') and 
      (has(br.value) and has(br.prototype) and br.proptype = 'description') 
return n.id as Node, ar.value as CCID, br.value as Description
0
votes

You can match relationships from two sides:

start n = Node(*)
match m<-[br]-n-[ar]->m
where has(ar.value) and has(ar.proptype) and ar.proptype = 'ccid' and 
has(br.value) and has(br.proptype) and br.proptype = 'description'
return ar.value, br.value