cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

cypher to display all connections to nodes

I want to create a cypher so that while executing it will display all outgoing connections and deeper connections and return statement should have only one variable 

MATCH p=(n:C)-[r:A|B]->(a:D) RETURN p
MATCH p=(c:D)-[r:E]->() RETURN p
return p
here it is necessary that return variable should be only one because I am connecting it with nodejs and if this code is used then it won't work
.run('
MATCH p=(n:C)-[r:A|B]->(a:D) RETURN p
MATCH p=(c:D)-[r:E]->() RETURN p
return p
')  
      .then(function (result){

          result.records.forEach(function(record){
              console.log("record = ", record);
              console.log("result = ", result)
              console.log("1] record._fields[0].properties = ",record._fields[0].end.properties);  
           //    res.send(record);          
          });
          res.send(result);

      })      
      .catch(function(err){
       console.log("inside catch = " + err);
   })

  })
2 REPLIES 2

Are these two paths related? As written, you will get the Cartesian product of the two path results. Also, each match can’t end in a ‘return’ if they are executed together. 

you could return both paths in your result and extract each in your code. Like this, but again you will get the Cartesian product of the two path results. That doesn’t seem like something you would want. 

MATCH p1=(n:C)-[r:A|B]->(a:D)
MATCH p2=(c:D)-[r:E]->()
return p1, p2
 
I notice the first path ends with a ‘D’ and the second starts with a ‘D’. Are you looking for one long path? If so, you can try this: 
MATCH p=(n:C)-[r:A|B]->(c:D)-[r:E]->() RETURN p
note: you can leave out binding variables if you don’t reference them in the query. 
if none of this was helpful, can you explain what your query is to achieve and we can try to help. 

I tried using this cypher but it didn't work I want to display all the nodes in JSON format such that all the nodes and if deeper connections attached to it exist then it should display like an array inside the main nodes