Is it possible to add a temporary property to a neo4j node for return only? : <p>I have been using cypher and neo4j for a while now, and I keep running into a similar problem again and again. </p>

<p>I would like to be able to add a "temporary" property to a node thats exists only in the returned data and is not persisted to the Neo4j database. </p>

<p>For example the current problem I am working on is given an N-ary tree structure in the graph database, I would like to return the children of a specific node, and an informational boolean letting me know weather those children have children. </p>

<p>The query to get this information is simple enough:</p>

<pre><code>MATCH (parent:Item { guid: "Identifier here" })-[:HASCHILD]-&gt;(child:Item)
OPTIONAL MATCH (child)-[:HASCHILD]-&gt;(grandchild:Item)
WITH parent, child, LENGTH(COLLECT(grandchild)) &gt; 0 AS has_children
</code></pre>

<p>Now I have the parent, child and a boolean letting me know weather there are further children. </p>

<p>What I would like to be able to do next is set the has_children boolean as a property on the child nodes, but just for returning the query, I don't need the property persisted.</p>

<p>I know there is are some solutions to get what I am looking for but none of them are specifically what I am looking for. </p>

<p>1) I could create a temporary node: (Continued from above query)</p>

<pre><code>...
WITH parent, child, LENGTH(COLLECT(grandchild)) &gt; 0 AS haschildren,
{
    childkey1: child.childkey1,
    childkey2: child.childkey2,
    ...
    has_children: haschildren
} AS tempnode
RETURN parent, tempnode
</code></pre>

<p>This solution is not great, you have to know the exact node type and all the properties of the node you are dealing with, it will not work in the general case. </p>

<p>2) I could SET and REMOVE the boolean, temporarily persisting it to the database (as described in <a href="https://stackoverflow.com/questions/28375229/neo4j-create-temp-variable-within-cypher">Neo4J create temp variable within Cypher</a>).</p>

<p>This is not great as it will cause multiple db writes (for add and remove). 
Also, it is not as dynamic as option 1 as it would only be able to handle simple types. (Option 1 can handle more complex cases, like adding a collection of nodes instead of a simple boolean).</p>

<p>As far as I know, these are the only options when it comes to temporary return data. I'm wondering am I missing any thing? Is it possible to make this more simple or dynamic? </p>

<p>Something along the lines of </p>

<pre><code> WITH parent, child, LENGTH(COLLECT(grandchild)) &gt; 0 AS haschildren,
 TEMPSET child.has_children = haschildren
</code></pre>

<p>Please note that I have simplified the examples given a little. 
I have run into this issue multiple times in different contexts in neo4j. Most times I either go with option 1, or build the correct structure by post-processing on the application side once the query returns. </p>

<p>Is there a better way?</p>
