windows 10 pro office 2019 pro office 365 pro windows 10 home windows 10 enterprise office 2019 home and business office 2016 pro windows 10 education visio 2019 microsoft project 2019 microsoft project 2016 visio professional 2016 windows server 2012 windows server 2016 windows server 2019 Betriebssysteme office software windows server https://softhier.com/ instagram takipçi instagram beğeni instagram görüntüleme instagram otomatik beğeni facebook beğeni facebook sayfa beğenisi facebook takipçi twitter takipçi twitter beğeni twitter retweet youtube izlenme youtube abone instagram

How to insert data into Firebase using Polymerfire (mutiple nodes + multiple paths)

Asked By: Anonymous

My use case is that I have an <iron-form> with a single <paper-textarea> field that accepts a string list of email addresses which I parse into an array, then I want to:

  1. Store the individual email addresses in my Firebase (for indexing and lookup purposes),
  2. at multiple locations (per data fan out technique),
  3. with a single write operation (because I don’t want to make 100 API calls if the list is that long) and
  4. without overwriting any existing data.

Specifically, I want to start with State A, as follows:

State A

my-app
 |
 - emails
 |  |
 |  - [email protected],com
 |     |- old: "data"
 |  - [email protected],com
 |     |- old: "data"
 - users
    |
    - c0djhbQi6vc4YMB-fDgJ

And achieve State B as follows:

State B

my-app
 |
 - emails
 |  |
 |  - [email protected],com
 |     |- old: "data"
 |  - [email protected],com
 |     |- old: "data"
 |  - [email protected],com
 |     |- new: "data"
 |  - [email protected],com
 |     |- new: "data"
 - users
    |
    - c0djhbQi6vc4YMB-fDgJ
       |
       - emails
          |
          - [email protected],com
             |- new: "data"
          - [email protected],com
             |- new: "data"

Notice: The {old: "data"} is not overwritten.

Background

I seek to extend this SO question and answer.

There, we inserted a single node in a new location with three options:

  1. using firebase-query
  2. JS SDK
  3. using firebase-document

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.

Similar to what’s shown here.

https://firebase.google.com/docs/database/web/read-and-write#update_specific_fields

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);
}

Also note, one of the comments mentions:

There’s no reason newPostKey above couldn’t be an email address…

The challenge is that I need to write multiple keys to multiple locations simultaneously in a single call.


Solution

Answered By: Anonymous

The Firebase Realtime Database supports arbitrarily complex atomic deep updates (blog post). It works like so:

  1. You can update any arbitrarily deep path with a single .update() call
  2. The full path on the key side of your update map will be replaced, so you must address subkeys directly if you don’t want to blow away the parent
  3. Paths are relative to your current ref

So let’s take your example:

var update = {};

update['emails/[email protected],com'] = {new: 'data'};
update['emails/[email protected],com'] = {new: 'data'};
update['users/c0djhbQi6vc4YMB-fDgJ/emails/[email protected],com'] = {new: 'data'};
update['users/c0djhbQi6vc4YMB-fDgJ/emails/[email protected],com'] = {new: 'data'};

firebase.database().ref().update(update);

This will update all of the locations simultaneously. To make it dynamic, simply use string interpolation when constructing the keys.

techinplanet staff


Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno
Alanya escort Manavgat escort Fethiye escort Kemer escort Didim escort http://www.kadinescort.net Gaziantep escort Denizli escort Adana escort Hatay escort Aydın escort İzmir escort Ankara escort Antalya escort Bursa escort İstanbul escort Kocaeli escort Konya escort Muğla escort Malatya escort Kayseri escort Mersin escort Samsun escort Sinop escort Tekirdağ escort Eskişehir escort Yalova escort Rize escort Amasya escort Balıkesir escort Çanakkale escort Bolu escort Erzincan escort Şırnak escort Van escort Yozgat escort Zonguldak escort Afyon escort Adıyaman escort Bilecik escort Aksaray escort Ağri escort Bitlis escort Siirt escort Çorum escort Burdur escort Diyarbakir escort Edirne escort Düzce escort Erzurum escort Kırklareli escort Giresun escort Kilis escort Kars escort Karabük escort Kırıkkale escort Mardin escort Kırşehir escort Maraş escort Manisa escort Muş escort Kastamonu escort Ordu escort Nevşehir escort Sakarya escort Osmaniye escort Şanliurfa escort Sivas escort Trabzon escort Tokat escort Ardahan escort Bartın escort Karaman escort Batman escort Bayburt escort Bingöl escort Elaziğ escort Gümüşhane escort Hakkari escort Isparta escort Uşak escort Igdır escort