title: Cloud Functions for Firebase: Increment Counter
body: <p>Is it acceptable to increment a counter with a realtime database trigger using transaction?</p>
  
  <pre><code>exports.incPostCount = functions.database.ref('/threadsMeta/{threadId}/posts')
  .onWrite(event =&gt; {
      admin.database().ref('/analytics/postCount')
      .transaction(count =&gt; {
          if (count === null) {
              return count = 1
          } else {
              return count + 1
          }
      })
  });
  </code></pre>