title: How to insert data into Firebase using Polymerfire (mutiple nodes + multiple paths)
body: <p>My use case is that I have an <code>&lt;iron-form&gt;</code> with a single <code>&lt;paper-textarea&gt;</code> field that accepts a string list of email addresses which I parse into an array, then I want to:</p>
  
  <ol>
  <li>Store the individual email addresses in my Firebase (for indexing and lookup purposes),</li>
  <li>at multiple locations (per <em>data fan out</em> technique),</li>
  <li>with a single write operation (because I don't want to make 100 API calls if the list is that long) and</li>
  <li>without overwriting any existing data.</li>
  </ol>
  
  <p>Specifically, I want to start with State A, as follows:</p>
  
  State A
  
  <pre><code>my-app
   |
   - emails
   |  |
   |  - email1@example,com
   |     |- old: "data"
   |  - email2@example,com
   |     |- old: "data"
   - users
      |
      - c0djhbQi6vc4YMB-fDgJ
  </code></pre>
  
  <p>And achieve State B as follows:</p>
  
  State B
  
  <pre><code>my-app
   |
   - emails
   |  |
   |  - email1@example,com
   |     |- old: "data"
   |  - email2@example,com
   |     |- old: "data"
   |  - email3@example,com
   |     |- new: "data"
   |  - email4@example,com
   |     |- new: "data"
   - users
      |
      - c0djhbQi6vc4YMB-fDgJ
         |
         - emails
            |
            - email3@example,com
               |- new: "data"
            - email4@example,com
               |- new: "data"
  </code></pre>
  
  <p>Notice: The <code>{old: "data"}</code> is not overwritten.</p>
  
  <h2>Background</h2>
  
  <p><a href="https://stackoverflow.com/q/40709896/1640892">I seek to extend this SO question and answer</a>.</p>
  
  <p>There, we inserted a single node in a new location with three options:</p>
  
  <ol>
  <li>using <code>firebase-query</code></li>
  <li>JS SDK</li>
  <li>using <code>firebase-document</code></li>
  </ol>
  
  <p>Now, I need to do the same type of insertion (without deletion or replacing old data) for multiple nodes (with a user defined, not autogenerated, key; i.e., keys are specific email addresses). I also need to use the data fan out technique to update multiple paths with a single write operation.</p>
  
  <p><a href="https://firebase.google.com/docs/database/web/read-and-write#update_specific_fields" rel="nofollow noreferrer">Similar to what's shown here</a>.</p>
  
  https://firebase.google.com/docs/database/web/read-and-write#update_specific_fields
  
  <pre><code>function writeNewPost(uid, username, picture, title, body) {
    // A post entry.
    var postData = {
      author: username,
      uid: uid,
      body: body,
      title: title,
      starCount: 0,
      authorPic: picture
    };
  
    // Get a key for a new Post.
    var newPostKey = firebase.database().ref().child('posts').push().key;
    // * * * * * * * * * * * * * * * *  
    // THE ABOVE LINE NEEDS TO CHANGE TO SUPPORT USER-GENERATED KEYS SUCH AS EMAIL ADDRESSES
    // * * * * * * * * * * * * * * * * 
  
    // Write the new post's data simultaneously in the posts list and the user's post list.
    var updates = {};
    updates['/posts/' + newPostKey] = postData;
    updates['/user-posts/' + uid + '/' + newPostKey] = postData;
  
    return firebase.database().ref().update(updates);
  }
  </code></pre>
  
  <p>Also note, one of the comments mentions:</p>
  
  <blockquote>
    <p>There's no reason <code>newPostKey</code> above couldn't be an email address...</p>
  </blockquote>
  
  <p>The challenge is that I need to write multiple keys to multiple locations simultaneously in a single call.</p>