Skip to content

Instantly share code, notes, and snippets.

@gigocabrera
Forked from katowulf/firebase_copy.js
Created August 5, 2016 20:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gigocabrera/12858269fc1a4b20df443c1a3d2a6adc to your computer and use it in GitHub Desktop.
Save gigocabrera/12858269fc1a4b20df443c1a3d2a6adc to your computer and use it in GitHub Desktop.
Move or copy a Firebase path to a new location
function copyFbRecord(oldRef, newRef) {
oldRef.once('value', function(snap) {
newRef.set( snap.value(), function(error) {
if( error && typeof(console) !== 'undefined' && console.error ) { console.error(error); }
});
});
}
function moveFbRecord(oldRef, newRef) {
oldRef.once('value', function(snap) {
newRef.set( snap.value(), function(error) {
if( !error ) { oldRef.remove(); }
else if( typeof(console) !== 'undefined' && console.error ) { console.error(error); }
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment