I'm running the following query in Neo4J and I'm getting an error. In a nutshell, I'm asking the database show me all nodes with the label "user" and, if it has a relationship, the type of the relationship and the label type of the node it's connected to.
START n=node(*) MATCH (n:user)-[r?]-(m) WHERE HAS (n.name) RETURN n, labels(n), type(r), labels(m), m.name;
An error occurs when a node of type user is found that doesn't have a node related to it. It seems to be blowing up on the labels(m) part. I would expect that if the node didn't exist, I would get a NULL returned instead of an error. This is how the type() function works. If no relationship is found, type() returns NULL.
Here is what my result looks like if I omit the labels(m) part...
==>+-----------------------------------------------------------------------------------------------------------------------------------+
==> | n | labels(n) | type(r) | m.name |
==> +-----------------------------------------------------------------------------------------------------------------------------------+
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | "vinniecontext" |
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | "vinniecontext" |
==> | Node[2557]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | "hasContext" | "vinniecontext" |
==> | Node[2558]{lastName:"b",mobilePhone:"b",status:"b",email:"b",name:"b",firstName:"b"} | ["user"] | <null> | <null> |
==> | Node[2559]{lastName:"c",mobilePhone:"c",status:"c",email:"c",name:"c",firstName:"c"} | ["user"] | <null> | <null> |
==> | Node[2560]{lastName:"a",mobilePhone:"a",status:"a",email:"a",name:"a",firstName:"a"} | ["user"] | <null> | <null> |
==> | Node[2561]{lastName:"b",mobilePhone:"b",status:"b",email:"b",name:"",firstName:"b"} | ["user"] | <null> | <null> |
==> +-----------------------------------------------------------------------------------------------------------------------------------+
How can I get the result that I want? I basically want a NULL value in the case where there is no connecting node, otherwise give me the label of the connecting node.
Thanks in advance!!