Skip to content

Instantly share code, notes, and snippets.

@Wizek
Forked from katowulf/firebase_copy.js
Last active August 2, 2016 21:42
Show Gist options
  • Save Wizek/370a84c363ab2a83a83f to your computer and use it in GitHub Desktop.
Save Wizek/370a84c363ab2a83a83f 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