javascript - How to duplicate a Firebase child with many records without downloading and uploading the data? -


i have firebase child 500k records. want duplicate child in order create backup of data (within same firebase). so, if child called lines, want duplicate new name such lines_backup_02_02_2016. once done want original lines left is.

is there way without grabbing datasnapshot via javascript (downloading data) , using set() create copy? example:

fb.child("lines").once('value', function(snapshot) {     fb.child("lines_backup_02_02_2016").set(snapshot.val());   }); 

with 500k records i'm finding takes longer i've been able wait far (for example, i've typed question while still waiting finish).

trying access/query node 500k child records bad idea. it's not need synchronize 500k lines users. please work hard on separating active historical data. current approach of creating backup copy great start that. delete nodes while you're writing them new location.

to data going "a bit involved". indeed involves first getting list of child keys shallow rest call:

https://yours.firebaseio.com/path-to-list.json?shallow=true 

then loop through keys , access each child in turn, regular javascript client:

ref.child('path-to-list').child(key).once('value', function(snapshot) {   ref.child('path-to-backup').child(key).set(snapshot.val(), function(error) {     if (!error) {       // delete original item, list stays small       snapshot.ref().remove();     }   });  }); 

this loop doesn't create problems, since you're not querying entire list. instead accessing specific child nodes directly, fine.

be sure throttle loop, because might otherwise swamp database small writes.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -