title: Firebase push and set multiple nodes atomically with security rules
body: <p>I've read <a href="https://stackoverflow.com/questions/29947898/firebase-data-consistency-across-multiple-nodes">Firebase data consistency across multiple nodes</a>, the multi update stuff works as expected, however I don't know how to do the following:</p>
  
  <p>Let's say I have 2 collections: <code>answers</code> and <code>posts</code>. Now I want to write an answer to a post and increment the answers counter on the post object keeping the data consistent between collections. So the actual objects look similar to these:</p>
  
  <p><strong>post</strong></p>
  
  <pre><code>{
     ...,
     answers: X
  }
  </code></pre>
  
  <p><strong>answer</strong></p>
  
  <pre><code>{
     postID: &lt;random string&gt;,
     ...
  }
  </code></pre>
  
  <p>As I said above, that link answers how to do a merged update, however, how can I be sure that the <code>answers</code> property will only be incremented/decremented (in case of deletion) by 1? What I have so far is this:</p>
  
  <pre><code>"answers": {
    ".validate": "newData.isNumber() &amp;&amp; (newData.val() === data.val() + 1 || newData.val() === data.val() - 1)"
  }
  </code></pre>
  
  <p>Obviously that would work (I assume, haven't tried), but that would still allow me to <strong>create</strong> a new answer and <strong>decrement</strong> the counter. How can I overcome that issue?</p>