The cypher query that ended up working for me was MATCH (n) OPTIONAL MATCH (n)-[r]->(m) RETURN n,r,m
function makeAllBlocksQuery(cb){
db.cypher({
query: "MATCH (n) OPTIONAL MATCH (n)-[r]->(m) RETURN n,r,m",
}, function(err,results){
var processedResults = handleAllBlocks(err, results);
cb(processedResults);
});
}
function handleAllBlocks(err, results) {
if (err) throw err;
if (!results) {
console.log('No blocks found.');
return [];
} else {
//first, form [_fromId, _toId] relationshipArray
var relationshipArray = new Array();
for (count = 0; count < Object.keys(results).length; count++) {
if(results[count].r !== null) {
var relationship = [results[count].r._fromId, results[count].r._toId];
relationshipArray.push(relationship);
}
}
var resultArray = new Array();
var repliedIdsArray = new Array();
//add nodes found in results to resultArray
//and add id property to properties for later
for (count = 0; count < Object.keys(results).length; count++) {
results[count].n.properties.id = results[count].n._id;
//iterate through the relationshipArray for each result
//and add all the replied Ids to the repliedIdsArray
for (relationshipcount = 0; relationshipcount < relationshipArray.length; relationshipcount++){
if (relationshipArray[relationshipcount][1] == results[count].n.properties.id) {
repliedIdsArray.push(relationshipArray[relationshipcount][0]);
}
}
//add the repliedIdsArray to the result's properties
results[count].n.properties.hasreplyto = repliedIdsArray;
repliedIdsArray = [];
//stringify so it can be sent to client more easily
resultArray.push(JSON.stringify(results[count].n.properties));
}
return resultArray;
}
}