title: Firebase how to prevent duplicate entries atomically
body: <p>I'm looking at using firebase as a data store for user data for a web app.  My current thought is to store each user's data using the timestamp of when they joined as the key referencing that user's data.  The advantage of this scheme is that it's a simple way to assign unique integer ids to users, and makes chronological sorting of users simple.</p>
  
  <p>A downside, however, is that if two <code>add user</code> requests are submitted with identical data, the app will happily add two separate entries, which is unideal.  I could shuffle things around (I'm starting to think I should use email as the key and prioritize by join data, rather than my current scheme), but suppose I don't want to.  Is there any way to prevent duplicate data?</p>
  
  <p>The naive approach would probably be just to do something like:</p>
  
  <pre><code>if(!searchFirebaseForUser(data)) {
      addUser(data);
  }
  </code></pre>
  
  <p>But this is definitely a race condition; it'd be easy for two requests to both query and find no user in the database, and both add.  I'd like to do this in a transaction, but it doesn't seem like the Firebase transaction support covers this case.  Is there any way to handle this?</p>