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.

Is there a way to return multiple aliases with a Neo4j call using the JS driver?

Hi again!
I was having issues trying to return multiple variables with the JS driver (returning both a & b in a single statement)

const drug = await session.run('MATCH (a:thing1 {id: $id})
 MATCH (b:thing2 {id: $id}) CREATE (a)-[r:$rel {weight: $weight})->(b) 
RETURN a, b'

If I return just one variable, the records.length correctly updates with however many "a" is, but if I try adding in another return variable (like a, b) it doesn't add it to the results.records with a. Would I just need another session.run statement to return the other variable, or is there something I'm missing?
Thanks 🙂
-Rachel

1 ACCEPTED SOLUTION

Hello,

The number of records is equal to the number of rows of results. When you have RETURN a, b this adds b as an additional column in the returned records, not as an additional record by itself.

Looking at the Neo4j from Javascript article, take a look at the last example:

var query="MATCH (n:User) RETURN n, labels(n) as l LIMIT {limit}"
var params={limit: 10}
var cb=function(err,data) { console.log(JSON.stringify(data)) }

cypher(query,params,cb)

{"results":[
  {"columns":["n","l"],
   "data":[
     {"row":[{"name":"Aran"},["User"]]}
    ]
  }],
 "errors":[]}

The variables in the RETURN do not change the number of records returned, but they do change the columns returned and the associated row results per record.

View solution in original post

2 REPLIES 2

Hello,

The number of records is equal to the number of rows of results. When you have RETURN a, b this adds b as an additional column in the returned records, not as an additional record by itself.

Looking at the Neo4j from Javascript article, take a look at the last example:

var query="MATCH (n:User) RETURN n, labels(n) as l LIMIT {limit}"
var params={limit: 10}
var cb=function(err,data) { console.log(JSON.stringify(data)) }

cypher(query,params,cb)

{"results":[
  {"columns":["n","l"],
   "data":[
     {"row":[{"name":"Aran"},["User"]]}
    ]
  }],
 "errors":[]}

The variables in the RETURN do not change the number of records returned, but they do change the columns returned and the associated row results per record.

Oh ok got it, thank you!