Hi Alx,
Most probably because your data/graph simply not fullful your total cypher statement, Remeber that your are matchning a pattern and you start with limiting it to users that has a uid property. For example the graph data below returns a resultset for each individually MATCH queries, however once chained, like your query, it fails to match that pattern. That is becuse there is no User that has uid property and other nodes that are connected via the LOCATED_IN (the cities they are living in) relationship, thus your query will return nil in the end.
So with this graph data:
CREATE (Pontus:User { uid:'Pontus Lundin',name:'Pontus Lundin' }),(John:User { uid: 'John Hellberg',name:'John Hellberg' }),(Jack:User { uid: 'Jack Hellberg',name:'Jack Hellberg' }),(Nisse:User { name: 'Nisse Larsson' }),(Kalle:User { name: 'Kalle Johansson' }),(Johan:User { name:'Johan Davidsson' }),(Ronny:User { name: 'Ronny Stork' }),(Micke:User { name: 'Mikael Jansson' }),(Anna:User { name: 'Anna Karlsson', sex:'female' }),(Sandra:User { name: 'Sandra Johansson', sex:'female' }),(Fredrik:User { name:'Fredrik Hansson' }),(Gothenburg:Location { name:'Gothenburg',dailyhits:1000000 }),(Stockholm:Location { name:'Stockholm',dailyhits:300000 }),(Sundsvall:Location { name:'Sundsvall',dailyhits:6000 }),(Malmo:Location { name:'Malmö',dailyhits:20000 }),
(Pontus)-[:LOCATED_IN]->(Gothenburg),
(Ronny)-[:LOCATED_IN]->(Sundsvall),
(Sandra)-[:LOCATED_IN]->(Sundsvall),
(Pontus)-[:TEXTED]->(Sandra),
(Pontus)-[:TEXTED]->(Fredrik),
(Jack)-[:LOCATED_IN]->(Malmo),
(John)-[:LOCATED_IN]->(Stockholm),
(Jack)-[:TEXTED]->(Pontus);
This pattern will return data:
MATCH (n:User)
WHERE HAS (n.uid)
return n;
As well as:
WITH COLLECT(DISTINCT
m.name) AS users1, COLLECT(DISTINCT
k.name) AS users2
RETURN users1+ users2
However if your data has connection that fullfulls your query then it works (now a User with uid lives in the same city as another node), like:
CREATE (Pontus:User { uid:'Pontus Lundin',name:'Pontus Lundin' }),(John:User { uid: 'John Hellberg',name:'John Hellberg' }),(Jack:User { uid: 'Jack Hellberg',name:'Jack Hellberg' }),(Nisse:User { name: 'Nisse Larsson' }),(Kalle:User { name: 'Kalle Johansson' }),(Johan:User { name:'Johan Davidsson' }),(Ronny:User { name: 'Ronny Stork' }),(Micke:User { name: 'Mikael Jansson' }),(Anna:User { name: 'Anna Karlsson', sex:'female' }),(Sandra:User { name: 'Sandra Johansson', sex:'female' }),(Fredrik:User { name:'Fredrik Hansson' }),(Gothenburg:Location { name:'Gothenburg',dailyhits:1000000 }),(Stockholm:Location { name:'Stockholm',dailyhits:300000 }),(Sundsvall:Location { name:'Sundsvall',dailyhits:6000 }),(Malmo:Location { name:'Malmö',dailyhits:20000 }),
(Pontus)-[:LOCATED_IN]->(Sundsvall),
(Ronny)-[:LOCATED_IN]->(Sundsvall),
(Sandra)-[:LOCATED_IN]->(Sundsvall),
(Pontus)-[:TEXTED]->(Sandra),
(Pontus)-[:TEXTED]->(Fredrik),
(Jack)-[:LOCATED_IN]->(Malmo),
(John)-[:LOCATED_IN]->(Stockholm),
(Jack)-[:TEXTED]->(Pontus);
If you still want to return *something* (if it makes sense for your result) event though the "match fails" you can use the OPTIONAL match like the one below:
MATCH (n:User)
WHERE HAS (n.uid)
OPTIONAL